A developer in Cloud Shell must quickly learn how many rows in the Orders table of a Cloud Spanner database are currently in the PENDING state. The database is named "sales" and is hosted in the Spanner instance "europe-inst". Without writing any code, which single gcloud command will return the desired count directly in the terminal?
gcloud spanner databases query sales --instance=europe-inst --dml='SELECT COUNT(*) FROM Orders WHERE status="PENDING";'
gcloud spanner sessions execute --instance=europe-inst --database=sales --query='SELECT COUNT(*) FROM Orders WHERE status="PENDING";'
gcloud spanner databases execute-sql sales --instance=europe-inst --sql='SELECT COUNT(*) FROM Orders WHERE status="PENDING";'
gcloud sql databases execute sales --instance=europe-inst --sql='SELECT COUNT(*) FROM Orders WHERE status="PENDING";'
The gcloud CLI provides the databases execute-sql sub-command for issuing ad-hoc SQL to a Cloud Spanner database. Supply the database name as the positional argument, specify the instance with --instance, and pass the SQL text with --sql.
The other choices fail for these reasons:
"gcloud spanner sessions execute" is not a valid gcloud command; sessions are managed by client libraries, not the CLI.
The gcloud sql command group manages Cloud SQL, not Cloud Spanner, so it cannot access a Spanner database.
"gcloud spanner databases query" is not a valid sub-command, and the flag --dml (or similar) does not exist; even if it did, a DML-specific flag would be unnecessary for a read-only SELECT statement.
Therefore, only the execute-sql invocation will successfully run the SELECT COUNT(*) query against the specified Spanner database.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is Cloud Spanner?
Open an interactive chat with Bash
How does gcloud execute-sql work?
Open an interactive chat with Bash
What is the difference between Cloud Spanner and Cloud SQL?
Open an interactive chat with Bash
What is Cloud Spanner, and how is it used in GCP?
Open an interactive chat with Bash
What are the key gcloud commands for interacting with Cloud Spanner?
Open an interactive chat with Bash
What is the difference between Cloud Spanner and Cloud SQL?
Open an interactive chat with Bash
GCP Associate Cloud Engineer
Ensuring successful operation of a cloud solution
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .