All Spanner code samples
This page contains code samples for Spanner. To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.
Read data in parallel
Read data in parallel by dividing the query into smaller pieces, or partitions, and fetching the partitions in parallel.
- Google Cloud
- Spanner
- Python
- Node JS
- JavaScript
- PHP
- Go
- C++
- C#
- Ruby
- Java
Field access on a STRUCT
Query data using field access on a STRUCT.
- Spanner
- Google Cloud
- PHP
- C++
- JavaScript
- Go
- Node JS
- Ruby
- Python
- Java
- C#
Query with INT parameter
Query data by using an INT parameter.
- Spanner
- Google Cloud
- Java
- Python
- C#
- Go
- Node JS
- PHP
- JavaScript
- Ruby
- C++
Mutations update data with NUMERIC
Update data in NUMERIC column by using mutations.
- Spanner
- Google Cloud
- PHP
- C++
- JavaScript
- Go
- Node JS
- Ruby
- Python
- Java
- C#
Update graph data with a graph query
Update data in a Spanner Graph using a graph query.
- Google Cloud
- Spanner
- Python
- Java
- C++
- Go
Query data with array of STRUCT
Query data by using an array of STRUCT objects.
- Spanner
- Google Cloud
- Java
- Node JS
- C++
- Python
- PHP
- C#
- JavaScript
- Go
- Ruby
Hibernate inheritance
Use hibernate inheritance and UUIDs to save a payment record in a database.
- Google Cloud
- Spanner
- Java
Query data with STRUCT
Query data by using a STRUCT object.
- Google Cloud
- Spanner
- C#
- Java
- Ruby
- PHP
- Python
- C++
- JavaScript
- Go
- Node JS
Create table with data types
Create a table with example data types.
- Google Cloud
- Spanner
- JavaScript
- C#
- Node JS
- Ruby
- Java
- Python
- C++
- Go
- PHP
Mutations update data
Update data by using mutations.
- Google Cloud
- Spanner
- Ruby
- C++
- C#
- Go
- Java
- Node JS
- Python
- PHP
- JavaScript
List backups
List all backups and access backup data using filters and paging.
- Google Cloud
- Spanner
- Ruby
- C++
- Python
- Go
- JavaScript
- Node JS
- PHP
- Java
- C#
Create backup
Create database backup that can be used to restore the database.
- Spanner
- Google Cloud
- C#
- C++
- Java
- JavaScript
- Go
- Python
- Node JS
- Ruby
- PHP
Create client with query options
Create a client with query options. The client can then be used to read, write, and run transactions.
- Spanner
- Google Cloud
- PHP
- Python
- Go
- Node JS
- Ruby
- JavaScript
- C++
- C#
- Java
Query data from a new column
Query data from a new column.
- Spanner
- Google Cloud
- Ruby
- Node JS
- C#
- PHP
- Python
- C++
- Go
- JavaScript
- Java
Create user-defined STRUCT
Create a user-defined STRUCT.
- Google Cloud
- Spanner
- C#
- C++
- PHP
- Go
- Java
- Ruby
- Python
- JavaScript
- Node JS
Query data in a graph with a parameter
Query data in a Spanner Graph using a parameter.
- Spanner
- Google Cloud
- C++
- Java
- Python
- Go
Update backup
Update a backup by retrieving the expiry time of a backup and extending it.
- Spanner
- Google Cloud
- Node JS
- Ruby
- C++
- JavaScript
- PHP
- Java
- C#
- Go
- Python
JDBC set statement for query options
Use the SET statement to specify query options by using JDBC.
- Google Cloud
- Spanner
- Java
Add NUMERIC column
Update a schema by adding a NUMERIC column.
- Spanner
- Google Cloud
- Go
- Ruby
- C#
- Python
- Node JS
- Java
- JavaScript
- C++
- PHP
Dataflow read all
Use SQL queries with the Dataflow connector to read data from all available tables in a database.
- Spanner
- Google Cloud
- Java
Query with BYTES parameter
Query data by using a BYTES parameter.
- Spanner
- Google Cloud
- Go
- Node JS
- Java
- JavaScript
- Ruby
- C++
- C#
- PHP
- Python
Field access on nested STRUCT
Query data using field access on a nested STRUCT.
- Google Cloud
- Spanner
- Node JS
- C++
- JavaScript
- Python
- Ruby
- PHP
- C#
- Go
- Java
Query with FLOAT parameter
Query data by using a FLOAT parameter.
- Google Cloud
- Spanner
- Go
- PHP
- C++
- Java
- JavaScript
- Node JS
- C#
- Ruby
- Python
Query with TIMESTAMP parameter
Query data by using a TIMESTAMP parameter.
- Spanner
- Google Cloud
- Java
- Ruby
- Node JS
- Python
- JavaScript
- Go
- C++
- PHP
- C#
DML write then read
Insert data and then read the inserted data.
- Spanner
- Google Cloud
- Ruby
- C#
- Node JS
- Java
- PHP
- C++
- Go
- Python
- JavaScript
Batch DML
Call multiple SQL statements in a single transaction by using batch DML.
- Spanner
- Google Cloud
- PHP
- Node JS
- Python
- Ruby
- Java
- C++
- Go
- C#
- JavaScript
Query data with commit timestamp
Query data from a table containing a commit TIMESTAMP column.
- Google Cloud
- Spanner
- JavaScript
- Java
- C++
- Python
- C#
- Ruby
- Node JS
- Go
- PHP
Bulk delete with partitioned DML
Bulk delete data by using a partitioned DML statement.
- Google Cloud
- Spanner
- Ruby
- Node JS
- Go
- Python
- Java
- C#
- JavaScript
- PHP
- C++
Create table with TIMESTAMP column
Create a table with a TIMESTAMP column.
- Google Cloud
- Spanner
- Python
- Go
- C++
- Ruby
- Java
- JavaScript
- C#
- PHP
- Node JS
Update graph data with DML
Update data in a Spanner Graph using DML.
- Google Cloud
- Spanner
- Go
- Java
- Python
- C++
Dataflow read with transaction
Use the Dataflow connector to read data from multiple tables at the same point in time to ensure data consistency by performing all of the reads in a single transaction.
- Google Cloud
- Spanner
- Java
Query with STRING parameter
Query data by using a STRING parameter.
- Spanner
- Google Cloud
- C++
- JavaScript
- Node JS
- Go
- Python
- C#
- Ruby
- Java
- PHP
Create storing index
Create a storing index.
- Google Cloud
- Spanner
- Node JS
- Java
- C++
- C#
- Python
- JavaScript
- Go
- PHP
- Ruby
Add column
Update a schema by adding a column.
- Spanner
- Google Cloud
- Go
- Java
- Python
- JavaScript
- Ruby
- C++
- Node JS
- C#
- PHP
Dataflow write with mutations
Use the Dataflow connector to write data by using mutations.
- Google Cloud
- Spanner
- Java
List database operations
List all operations running on the database and list the percentage complete for each operation.
- Spanner
- Google Cloud
- C#
- C++
- Ruby
- JavaScript
- PHP
- Node JS
- Python
- Java
- Go
Query with DATE parameter
Query data by using a DATE parameter.
- Spanner
- Google Cloud
- C++
- PHP
- Go
- Node JS
- Java
- JavaScript
- Python
- Ruby
- C#
Bulk update with partitioned DML
Bulk update data by using a partitioned DML statement.
- Spanner
- Google Cloud
- Ruby
- PHP
- C++
- Java
- Go
- JavaScript
- C#
- Python
- Node JS
JDBC connection with query options
Set connection query options by using JDBC.
- Spanner
- Google Cloud
- Java
Insert graph data with DML
Insert data into a Spanner Graph using DML.
- Google Cloud
- Spanner
- Python
- C++
- Go
- Java
Dataflow read api
Use the Dataflow connector to read from a database without using a query by specifying a table name and a list of columns.
- Google Cloud
- Spanner
- Java
Query data with parameter
Query data by using a parameter.
- Google Cloud
- Spanner
- JavaScript
- Java
- Ruby
- C#
- Python
- PHP
- Go
- Node JS
- C++
Query with ARRAY parameter
Query data by using an ARRAY parameter.
- Spanner
- Google Cloud
- Java
- Go
- JavaScript
- C++
- Ruby
- Node JS
- Python
- PHP
- C#
List backup operations
List all create backup operations running on the database and list the percentage complete for each operation.
- Google Cloud
- Spanner
- C++
- PHP
- Node JS
- Ruby
- Python
- JavaScript
- C#
- Java
- Go
Read/write transaction
Use a read/write transaction.
- Google Cloud
- Spanner
- C++
- PHP
- Python
- Go
- Java
- Ruby
- JavaScript
- Node JS
- C#
Dataflow write group
Use the Dataflow connector to write data by using a MutationGroup class to ensure that a group of mutations is applied atomically.
- Google Cloud
- Spanner
- Java
DML update commit timestamp
Write a commit timestamp by using a DML statement.
- Spanner
- Google Cloud
- Java
- C#
- Ruby
- C++
- Node JS
- PHP
- Python
- Go
- JavaScript
Create STRUCT object with data
Create a STRUCT object populated with data.
- Spanner
- Google Cloud
- Ruby
- Java
- Python
- C++
- Node JS
- C#
- Go
- JavaScript
- PHP
Add TIMESTAMP column
Update a schema by adding a TIMESTAMP column.
- Google Cloud
- Spanner
- Go
- Python
- JavaScript
- Ruby
- Node JS
- Java
- PHP
- C#
- C++
Mutations write data with TIMESTAMP column
Write data into a table containing a TIMESTAMP column by using mutations.
- Google Cloud
- Spanner
- JavaScript
- Python
- C#
- C++
- Go
- Ruby
- PHP
- Node JS
- Java
Query with BOOL parameter
Query data by using a BOOL parameter.
- Google Cloud
- Spanner
- Ruby
- C++
- C#
- Go
- Java
- Node JS
- Python
- PHP
- JavaScript
Restore database from backup
Restore a database from a backup.
- Spanner
- Google Cloud
- Node JS
- Go
- Ruby
- PHP
- JavaScript
- Python
- Java
- C#
- C++
Mutations write data for STRUCT queries
Insert data used for STRUCT queries.
- Google Cloud
- Spanner
- JavaScript
- C#
- Node JS
- Python
- PHP
- Java
- Go
- C++
- Ruby
Delete data
Delete individual rows from a table.
- Spanner
- Google Cloud
- C++
- Java
- Ruby
- PHP
- Node JS
- C#
- JavaScript
- Python
- Go
Create database with a property graph
Create a database using a property graph.
- Google Cloud
- Spanner
- Go
- C++
- Java
- Python
Read data with index
Read data by using an index.
- Spanner
- Google Cloud
- C#
- Go
- JavaScript
- PHP
- Python
- Node JS
- C++
- Java
- Ruby
Query data with index
Query data by using an index.
- Spanner
- Google Cloud
- Node JS
- C#
- Go
- Ruby
- Java
- Python
- C++
- PHP
- JavaScript
Set custom timeout and retry
Set custom timeout and retry for request settings.
- Google Cloud
- Spanner
- Python
- C++
- JavaScript
- Node JS
- C#
- Ruby
- Java
- Go
Cancel backup create operation
Cancel a create backup database operation.
- Google Cloud
- Spanner
- Go
- JavaScript
- Java
- Node JS
- C++
- C#
- Ruby
- Python
- PHP
Mutations update data with TIMESTAMP
Update data in a table containing a TIMESTAMP column by using mutations.
- Spanner
- Google Cloud
- Ruby
- C#
- Node JS
- C++
- Go
- PHP
- Java
- JavaScript
- Python
DML delete data
Delete rows that match a WHERE condition by using DML.
- Google Cloud
- Spanner
- PHP
- Node JS
- Go
- Python
- Ruby
- C#
- C++
- Java
- JavaScript
Read-only transaction
Use a read-only transaction.
- Spanner
- Google Cloud
- C#
- PHP
- Node JS
- C++
- Ruby
- Python
- Go
- JavaScript
- Java
Mutations write data types data
Insert data into a table with example data types by using mutations.
- Spanner
- Google Cloud
- C++
- PHP
- C#
- Node JS
- Python
- Go
- Java
- JavaScript
- Ruby
DML write single row
Insert a single row by using DML.
- Google Cloud
- Spanner
- Go
- JavaScript
- PHP
- Node JS
- Python
- C++
- Ruby
- C#
- Java
Dataflow read
Use a SQL query with the Dataflow connector to read data from all the columns and rows in the specified table.
- Google Cloud
- Spanner
- Java
Mutations write data
Insert several rows of data into a table by using mutations.
- Google Cloud
- Spanner
- Java
- Ruby
- PHP
- JavaScript
- Go
- Python
- C++
- C#
- Node JS
Query with query options
Specify query options.
- Google Cloud
- Spanner
- Go
- Python
- Node JS
- JavaScript
- C#
- PHP
- Ruby
- C++
- Java
Create STRUCT object array with data
Create an array of STRUCT objects populated with data.
- Spanner
- Google Cloud
- Java
- JavaScript
- Ruby
- Go
- C#
- Node JS
- PHP
- C++
- Python
DML update data with STRUCT
Update data by using DML with a STRUCT object.
- Spanner
- Google Cloud
- Python
- JavaScript
- Node JS
- C++
- Go
- Java
- Ruby
- C#
- PHP
Query with NUMERIC parameter
Query data by using a NUMERIC parameter.
- Spanner
- Google Cloud
- Node JS
- Python
- C++
- PHP
- Ruby
- Go
- JavaScript
- C#
- Java