gcloud beta spanner databases execute-sql Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud beta spanner databases execute-sql - executes a SQL query against a Cloud Spanner database
- SYNOPSIS
gcloud beta spanner databases execute-sql(DATABASE:--instance=INSTANCE)--sql=SQL[--database-role=DATABASE_ROLE][--enable-partitioned-dml][--priority=PRIORITY][--query-mode=QUERY_MODE; default="NORMAL"][--timeout=TIMEOUT; default="10m"][--read-timestamp=TIMESTAMP|--strong][GCLOUD_WIDE_FLAG …]
- DESCRIPTION
(BETA)Executes a SQL query against a Cloud Spanner database.- EXAMPLES
- To execute a SQL SELECT statement against example-database underexample-instance, run:
gcloudbetaspannerdatabasesexecute-sqlexample-database--instance=example-instance--sql='SELECT * FROM MyTable WHERE MyKey = 1' - POSITIONAL ARGUMENTS
- Database resource - The Cloud Spanner database to execute the SQL query against.The arguments in this group can be used to specify the attributes of thisresource. (NOTE) Some attributes are not given arguments in this group but canbe set in other ways.
To set the
projectattribute:- provide the argument
databaseon the command line with a fullyspecified name; - provide the argument
--projecton the command line; - set the property
core/project.
This must be specified.
DATABASE- ID of the database or fully qualified identifier for the database.
To set the
databaseattribute:- provide the argument
databaseon the command line.
This positional argument must be specified if any of the other arguments in thisgroup are specified.
- provide the argument
--instance=INSTANCE- The Cloud Spanner instance for the database.
To set the
instanceattribute:- provide the argument
databaseon the command line with a fullyspecified name; - provide the argument
--instanceon the command line; - set the property
spanner/instance.
- provide the argument
- provide the argument
- Database resource - The Cloud Spanner database to execute the SQL query against.The arguments in this group can be used to specify the attributes of thisresource. (NOTE) Some attributes are not given arguments in this group but canbe set in other ways.
- REQUIRED FLAGS
--sql=SQL- The SQL query to issue to the database. Cloud Spanner SQL is described athttps://cloud.google.com/spanner/docs/query-syntax
- OPTIONAL FLAGS
--database-role=DATABASE_ROLE- Database role user assumes while accessing the database.
--enable-partitioned-dml- Execute DML statement using Partitioned DML
--priority=PRIORITY- The priority for the execute SQL request.
PRIORITYmustbe one of:high,low,medium,unspecified. --query-mode=QUERY_MODE; default="NORMAL"- Mode in which the query must be processed.
QUERY_MODEmust be one of:NORMAL- Returns only the query result, without any information about the query plan.
PLAN- Returns only the query plan, without any result rows or execution statisticsinformation.
PROFILE- Returns the query plan, overall execution statistics, operator-level executionstatistics, along with the result rows.
WITH_PLAN_AND_STATS- Returns the query plan, overall (but not operator-level) execution statistics,along with the results.
WITH_STATS- Returns the overall (but not operator-level) execution statistics along with theresults.
--timeout=TIMEOUT; default="10m"- Maximum time to wait for the SQL query to complete. See $gcloud topic datetimes forinformation on duration formats.
- Read-only query timestamp bound. The default is --strong. Seehttps://cloud.google.com/spanner/docs/timestamp-bounds.
At most one of these can be specified:
--read-timestamp=TIMESTAMP- Perform a query at the given timestamp.
--strong- Perform a strong query.
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- This command is currently in beta and might change without notice. Thesevariants are also available:
gcloudspannerdatabasesexecute-sqlgcloudalphaspannerdatabasesexecute-sql
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-07 UTC.