Method: projects.instances.databases.sessions.read

Reads rows from the database using key lookups and scans, as a simple key/value style alternative to sessions.executeSql. This method cannot be used to return a result set larger than 10 MiB; if the read matches more data than that, the read fails with a FAILED_PRECONDITION error.

Reads inside read-write transactions might return ABORTED. If this occurs, the application should restart the transaction from the beginning. See Transaction for more details.

Larger result sets can be yielded in streaming fashion by calling sessions.streamingRead instead.

HTTP request

POST https://spanner.googleapis.com/v1/{session=projects/*/instances/*/databases/*/sessions/*}:read

The URL uses Google API HTTP annotation syntax.

Path parameters

Parameters
session

string

Required. The session in which the read should be performed.

Authorization requires the following Google IAM permission on the specified resource session:

  • spanner.databases.read

Request body

The request body contains data with the following structure:

JSON representation
{
  "transaction": {
    object(TransactionSelector)
  },
  "table": string,
  "index": string,
  "columns": [
    string
  ],
  "keySet": {
    object(KeySet)
  },
  "limit": string,
  "resumeToken": string,
  "partitionToken": string,
}
Fields
transaction

object(TransactionSelector)

The transaction to use. If none is provided, the default is a temporary read-only transaction with strong concurrency.

table

string

Required. The name of the table in the database to be read.

index

string

If non-empty, the name of an index on table. This index is used instead of the table primary key when interpreting keySet and sorting result rows. See keySet for further information.

columns[]

string

The columns of table to be returned for each row matching this request.

keySet

object(KeySet)

Required. keySet identifies the rows to be yielded. keySet names the primary keys of the rows in table to be yielded, unless index is present. If index is present, then keySet instead names index keys in index.

If the partitionToken field is empty, rows are yielded in table primary key order (if index is empty) or index key order (if index is non-empty). If the partitionToken field is not empty, rows will be yielded in an unspecified order.

It is not an error for the keySet to name rows that do not exist in the database. sessions.read yields nothing for nonexistent rows.

limit

string (int64 format)

If greater than zero, only the first limit rows are yielded. If limit is zero, the default is no limit. A limit cannot be specified if partitionToken is set.

resumeToken

string (bytes format)

If this request is resuming a previously interrupted read, resumeToken should be copied from the last PartialResultSet yielded before the interruption. Doing this enables the new read to resume where the last read left off. The rest of the request parameters must exactly match the request that yielded this token.

A base64-encoded string.

partitionToken

string (bytes format)

If present, results will be restricted to the specified partition previously created using sessions.partitionRead(). There must be an exact match for the values of fields common to this message and the PartitionReadRequest message used to create this partitionToken.

A base64-encoded string.

Response body

If successful, the response body contains an instance of ResultSet.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/spanner.data
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Auth Guide.

Try it!

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Spanner Documentation