gcloud alpha spanner databases execute-sql

NAME
gcloud alpha spanner databases execute-sql - executes a SQL query against a Cloud Spanner database
SYNOPSIS
gcloud alpha 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
(ALPHA) Executes a SQL query against a Cloud Spanner database.
EXAMPLES
To execute a SQL SELECT statement against example-database underexample-instance, run:
gcloudalphaspannerdatabasesexecute-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 theproject attribute:

  • provide the argumentdatabase on the command line with a fullyspecified name;
  • provide the argument--project on the command line;
  • set the propertycore/project.

This must be specified.

DATABASE
ID of the database or fully qualified identifier for the database.

To set thedatabase attribute:

  • provide the argumentdatabase on the command line.

This positional argument must be specified if any of the other arguments in thisgroup are specified.

--instance=INSTANCE
The Cloud Spanner instance for the database.

To set theinstance attribute:

  • provide the argumentdatabase on the command line with a fullyspecified name;
  • provide the argument--instance on the command line;
  • set the propertyspanner/instance.
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.PRIORITY mustbe 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 help for details.

NOTES
This command is currently in alpha and might change without notice. If thiscommand fails with API permission errors despite specifying the correct project,you might be trying to access an API with an invitation-only early accessallowlist. These variants are also available:
gcloudspannerdatabasesexecute-sql
gcloudbetaspannerdatabasesexecute-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.