# Cloud Spanner API - Class Google::Cloud::Spanner::Snapshot (v2.36.0)

2.36.0 (latest) 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.0 2.24.0 2.23.0 2.22.0 2.21.0 2.20.0 2.19.1 2.18.1 2.17.0 2.16.1 2.15.0 2.14.0 2.13.0 2.12.1 2.11.0 Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Snapshot.

## Snapshot

A snapshot in Cloud Spanner is a set of reads that execute atomically at
a single logical point in time across columns, rows, and tables in a
database.

## Inherits

- Object

## Example

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

## Methods

### #execute

    def execute(sql, params: nil, types: nil, query_options: nil, request_options: nil, call_options: nil, directed_read_options: nil) -> Google::Cloud::Spanner::Results

**Alias Of** : [#execute_query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_query_instance_) Executes a SQL query.

The following settings can be provided:

- `:exclude_replicas` (Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.
- `:include_replicas` (Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
**Parameters**

- **sql** (String) --- The SQL query string. See [Query
  syntax](https://cloud.google.com/spanner/docs/query-syntax).


  The SQL query string can contain parameter placeholders. A parameter
  placeholder consists of "@" followed by the parameter name.
  Parameter names consist of any combination of letters, numbers, and
  underscores.
- **params** (Hash) *(defaults to: nil)* --- SQL parameters for the query string. The parameter placeholders, minus the "@", are the the hash keys, and the literal values are the hash values. If the query string contains something like "WHERE id \> @msg_id", then the params must contain something like `:msg_id => 1`.


  Ruby types are mapped to Spanner types as follows:

  \| Spanner \| Ruby \| Notes \|
  \|---\|---\|---\|
  \| `BOOL` \| `true`/`false` \| \|
  \| `INT64` \| `Integer` \| \|
  \| `FLOAT64` \| `Float` \| \|
  \| `FLOAT32` \| `Float` \| \|
  \| `NUMERIC` \| `BigDecimal` \| \|
  \| `STRING` \| `String` \| \|
  \| `UUID` \| `String` \| \|
  \| `DATE` \| `Date` \| \|
  \| `TIMESTAMP` \| `Time`, `DateTime` \| \|
  \| `BYTES` \| `File`, `IO`, `StringIO`, or similar \| \|
  \| `ARRAY` \| `Array` \| Nested arrays are not supported. \|
  \| `STRUCT` \| `Hash`, [Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") \| \|

  See [Data
  types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).

  See [Data Types - Constructing a
  STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).
- **types** (Hash) *(defaults to: nil)* --- Types of the SQL parameters in `params`. It is not always possible for Cloud Spanner to infer the right SQL type from a value in `params`. In these cases, the `types` hash must be used to specify the SQL type for these values.


  The keys of the hash should be query string parameter placeholders,
  minus the "@". The values of the hash should be Cloud Spanner type
  codes from the following list:
  - `:BOOL`
  - `:BYTES`
  - `:DATE`
  - `:FLOAT64`
  - `:FLOAT32`
  - `:NUMERIC`
  - `:INT64`
  - `:STRING`
  - `:TIMESTAMP`
  - `:UUID`
  - `Array` - Lists are specified by providing the type code in an array. For example, an array of integers are specified as `[:INT64]`.
  - [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") - Types for STRUCT values (`Hash`/[Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") objects) are specified using a [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") object.

  Types are optional.
- **query_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  query options for executing SQL query. Query options are optional.
  The following settings can be provided:
  - `:optimizer_version` (String) The version of optimizer to use. Empty to use database default. "latest" to use the latest available optimizer version.
  - `:optimizer_statistics_package` (String) Statistics package to use. Empty to use the database default.
- **request_options** (Hash) *(defaults to: nil)* ---

  Common request options.
  - `:priority` (Symbol) The relative priority for requests. The priority acts as a hint to the Cloud Spanner scheduler and does not guarantee priority or order of execution. Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`, `:PRIORITY_HIGH`. If priority not set then default is `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
  - `:tag` (String) A per-request tag which can be applied to queries or reads, used for statistics collection. Tag must be a valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
- **call_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  call options, e.g., timeout, retries, etc. Call options are
  optional. The following settings can be provided:
  - `:timeout` (Numeric) A numeric value of custom timeout in seconds that overrides the default setting.
  - `:retry_policy` (Hash) A hash of values that overrides the default setting of retry policy with the following keys:
    - `:initial_delay` (`Numeric`) - The initial delay in seconds.
    - `:max_delay` (`Numeric`) - The max delay in seconds.
    - `:multiplier` (`Numeric`) - The incremental backoff multiplier.
    - `:retry_codes` (`Array<String>`) - The error codes that should trigger a retry.
- **directed_read_options** (Hash) *(defaults to: nil)* --- Client options used to set the directed_read_options for all ReadRequests and ExecuteSqlRequests that indicates which replicas or regions should be used for non-transactional reads or queries. Will represent [`Google::Cloud::Spanner::V1::DirectedReadOptions`](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-DirectedReadOptions)
**Returns**

- ([Google::Cloud::Spanner::Results](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Results)) --- The results of the query execution.
**Examples**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query parameters:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users " \
                        "WHERE active = @active",
                        params: { active: true }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query with a SQL STRUCT query parameter as a Hash:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_hash = { id: 1, name: "Charlie", active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Specify the SQL STRUCT type using Fields object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
   user_hash = { id: 1, name: nil, active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash },
    types: { user_struct: user_type }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Or, query with a SQL STRUCT as a typed Data object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
user_data = user_type.struct id: 1, name: nil, active: false

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_data }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query options:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", query_options: {
      optimizer_version: "1",
      optimizer_statistics_package: "auto_20191128_14_47_22UTC"
    }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using custom timeout and retry policy:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

timeout = 30.0
retry_policy = {
  initial_delay: 0.25,
  max_delay:     32.0,
  multiplier:    1.3,
  retry_codes:   ["UNAVAILABLE"]
}
call_options = { timeout: timeout, retry_policy: retry_policy }

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", call_options: call_options

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #execute_query

    def execute_query(sql, params: nil, types: nil, query_options: nil, request_options: nil, call_options: nil, directed_read_options: nil) -> Google::Cloud::Spanner::Results

**Aliases**

- [#execute](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_instance_)
- [#query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_query_instance_)
- [#execute_sql](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_sql_instance_)
Executes a SQL query.

The following settings can be provided:

- `:exclude_replicas` (Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.
- `:include_replicas` (Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
**Parameters**

- **sql** (String) --- The SQL query string. See [Query
  syntax](https://cloud.google.com/spanner/docs/query-syntax).


  The SQL query string can contain parameter placeholders. A parameter
  placeholder consists of "@" followed by the parameter name.
  Parameter names consist of any combination of letters, numbers, and
  underscores.
- **params** (Hash) *(defaults to: nil)* --- SQL parameters for the query string. The parameter placeholders, minus the "@", are the the hash keys, and the literal values are the hash values. If the query string contains something like "WHERE id \> @msg_id", then the params must contain something like `:msg_id => 1`.


  Ruby types are mapped to Spanner types as follows:

  \| Spanner \| Ruby \| Notes \|
  \|---\|---\|---\|
  \| `BOOL` \| `true`/`false` \| \|
  \| `INT64` \| `Integer` \| \|
  \| `FLOAT64` \| `Float` \| \|
  \| `FLOAT32` \| `Float` \| \|
  \| `NUMERIC` \| `BigDecimal` \| \|
  \| `STRING` \| `String` \| \|
  \| `UUID` \| `String` \| \|
  \| `DATE` \| `Date` \| \|
  \| `TIMESTAMP` \| `Time`, `DateTime` \| \|
  \| `BYTES` \| `File`, `IO`, `StringIO`, or similar \| \|
  \| `ARRAY` \| `Array` \| Nested arrays are not supported. \|
  \| `STRUCT` \| `Hash`, [Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") \| \|

  See [Data
  types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).

  See [Data Types - Constructing a
  STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).
- **types** (Hash) *(defaults to: nil)* --- Types of the SQL parameters in `params`. It is not always possible for Cloud Spanner to infer the right SQL type from a value in `params`. In these cases, the `types` hash must be used to specify the SQL type for these values.


  The keys of the hash should be query string parameter placeholders,
  minus the "@". The values of the hash should be Cloud Spanner type
  codes from the following list:
  - `:BOOL`
  - `:BYTES`
  - `:DATE`
  - `:FLOAT64`
  - `:FLOAT32`
  - `:NUMERIC`
  - `:INT64`
  - `:STRING`
  - `:TIMESTAMP`
  - `:UUID`
  - `Array` - Lists are specified by providing the type code in an array. For example, an array of integers are specified as `[:INT64]`.
  - [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") - Types for STRUCT values (`Hash`/[Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") objects) are specified using a [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") object.

  Types are optional.
- **query_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  query options for executing SQL query. Query options are optional.
  The following settings can be provided:
  - `:optimizer_version` (String) The version of optimizer to use. Empty to use database default. "latest" to use the latest available optimizer version.
  - `:optimizer_statistics_package` (String) Statistics package to use. Empty to use the database default.
- **request_options** (Hash) *(defaults to: nil)* ---

  Common request options.
  - `:priority` (Symbol) The relative priority for requests. The priority acts as a hint to the Cloud Spanner scheduler and does not guarantee priority or order of execution. Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`, `:PRIORITY_HIGH`. If priority not set then default is `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
  - `:tag` (String) A per-request tag which can be applied to queries or reads, used for statistics collection. Tag must be a valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
- **call_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  call options, e.g., timeout, retries, etc. Call options are
  optional. The following settings can be provided:
  - `:timeout` (Numeric) A numeric value of custom timeout in seconds that overrides the default setting.
  - `:retry_policy` (Hash) A hash of values that overrides the default setting of retry policy with the following keys:
    - `:initial_delay` (`Numeric`) - The initial delay in seconds.
    - `:max_delay` (`Numeric`) - The max delay in seconds.
    - `:multiplier` (`Numeric`) - The incremental backoff multiplier.
    - `:retry_codes` (`Array<String>`) - The error codes that should trigger a retry.
- **directed_read_options** (Hash) *(defaults to: nil)* --- Client options used to set the directed_read_options for all ReadRequests and ExecuteSqlRequests that indicates which replicas or regions should be used for non-transactional reads or queries. Will represent [`Google::Cloud::Spanner::V1::DirectedReadOptions`](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-DirectedReadOptions)
**Returns**

- ([Google::Cloud::Spanner::Results](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Results)) --- The results of the query execution.
**Examples**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query parameters:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users " \
                        "WHERE active = @active",
                        params: { active: true }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query with a SQL STRUCT query parameter as a Hash:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_hash = { id: 1, name: "Charlie", active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Specify the SQL STRUCT type using Fields object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
   user_hash = { id: 1, name: nil, active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash },
    types: { user_struct: user_type }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Or, query with a SQL STRUCT as a typed Data object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
user_data = user_type.struct id: 1, name: nil, active: false

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_data }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query options:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", query_options: {
      optimizer_version: "1",
      optimizer_statistics_package: "auto_20191128_14_47_22UTC"
    }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using custom timeout and retry policy:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

timeout = 30.0
retry_policy = {
  initial_delay: 0.25,
  max_delay:     32.0,
  multiplier:    1.3,
  retry_codes:   ["UNAVAILABLE"]
}
call_options = { timeout: timeout, retry_policy: retry_policy }

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", call_options: call_options

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #execute_sql

    def execute_sql(sql, params: nil, types: nil, query_options: nil, request_options: nil, call_options: nil, directed_read_options: nil) -> Google::Cloud::Spanner::Results

**Alias Of** : [#execute_query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_query_instance_) Executes a SQL query.

The following settings can be provided:

- `:exclude_replicas` (Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.
- `:include_replicas` (Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
**Parameters**

- **sql** (String) --- The SQL query string. See [Query
  syntax](https://cloud.google.com/spanner/docs/query-syntax).


  The SQL query string can contain parameter placeholders. A parameter
  placeholder consists of "@" followed by the parameter name.
  Parameter names consist of any combination of letters, numbers, and
  underscores.
- **params** (Hash) *(defaults to: nil)* --- SQL parameters for the query string. The parameter placeholders, minus the "@", are the the hash keys, and the literal values are the hash values. If the query string contains something like "WHERE id \> @msg_id", then the params must contain something like `:msg_id => 1`.


  Ruby types are mapped to Spanner types as follows:

  \| Spanner \| Ruby \| Notes \|
  \|---\|---\|---\|
  \| `BOOL` \| `true`/`false` \| \|
  \| `INT64` \| `Integer` \| \|
  \| `FLOAT64` \| `Float` \| \|
  \| `FLOAT32` \| `Float` \| \|
  \| `NUMERIC` \| `BigDecimal` \| \|
  \| `STRING` \| `String` \| \|
  \| `UUID` \| `String` \| \|
  \| `DATE` \| `Date` \| \|
  \| `TIMESTAMP` \| `Time`, `DateTime` \| \|
  \| `BYTES` \| `File`, `IO`, `StringIO`, or similar \| \|
  \| `ARRAY` \| `Array` \| Nested arrays are not supported. \|
  \| `STRUCT` \| `Hash`, [Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") \| \|

  See [Data
  types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).

  See [Data Types - Constructing a
  STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).
- **types** (Hash) *(defaults to: nil)* --- Types of the SQL parameters in `params`. It is not always possible for Cloud Spanner to infer the right SQL type from a value in `params`. In these cases, the `types` hash must be used to specify the SQL type for these values.


  The keys of the hash should be query string parameter placeholders,
  minus the "@". The values of the hash should be Cloud Spanner type
  codes from the following list:
  - `:BOOL`
  - `:BYTES`
  - `:DATE`
  - `:FLOAT64`
  - `:FLOAT32`
  - `:NUMERIC`
  - `:INT64`
  - `:STRING`
  - `:TIMESTAMP`
  - `:UUID`
  - `Array` - Lists are specified by providing the type code in an array. For example, an array of integers are specified as `[:INT64]`.
  - [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") - Types for STRUCT values (`Hash`/[Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") objects) are specified using a [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") object.

  Types are optional.
- **query_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  query options for executing SQL query. Query options are optional.
  The following settings can be provided:
  - `:optimizer_version` (String) The version of optimizer to use. Empty to use database default. "latest" to use the latest available optimizer version.
  - `:optimizer_statistics_package` (String) Statistics package to use. Empty to use the database default.
- **request_options** (Hash) *(defaults to: nil)* ---

  Common request options.
  - `:priority` (Symbol) The relative priority for requests. The priority acts as a hint to the Cloud Spanner scheduler and does not guarantee priority or order of execution. Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`, `:PRIORITY_HIGH`. If priority not set then default is `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
  - `:tag` (String) A per-request tag which can be applied to queries or reads, used for statistics collection. Tag must be a valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
- **call_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  call options, e.g., timeout, retries, etc. Call options are
  optional. The following settings can be provided:
  - `:timeout` (Numeric) A numeric value of custom timeout in seconds that overrides the default setting.
  - `:retry_policy` (Hash) A hash of values that overrides the default setting of retry policy with the following keys:
    - `:initial_delay` (`Numeric`) - The initial delay in seconds.
    - `:max_delay` (`Numeric`) - The max delay in seconds.
    - `:multiplier` (`Numeric`) - The incremental backoff multiplier.
    - `:retry_codes` (`Array<String>`) - The error codes that should trigger a retry.
- **directed_read_options** (Hash) *(defaults to: nil)* --- Client options used to set the directed_read_options for all ReadRequests and ExecuteSqlRequests that indicates which replicas or regions should be used for non-transactional reads or queries. Will represent [`Google::Cloud::Spanner::V1::DirectedReadOptions`](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-DirectedReadOptions)
**Returns**

- ([Google::Cloud::Spanner::Results](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Results)) --- The results of the query execution.
**Examples**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query parameters:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users " \
                        "WHERE active = @active",
                        params: { active: true }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query with a SQL STRUCT query parameter as a Hash:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_hash = { id: 1, name: "Charlie", active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Specify the SQL STRUCT type using Fields object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
   user_hash = { id: 1, name: nil, active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash },
    types: { user_struct: user_type }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Or, query with a SQL STRUCT as a typed Data object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
user_data = user_type.struct id: 1, name: nil, active: false

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_data }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query options:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", query_options: {
      optimizer_version: "1",
      optimizer_statistics_package: "auto_20191128_14_47_22UTC"
    }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using custom timeout and retry policy:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

timeout = 30.0
retry_policy = {
  initial_delay: 0.25,
  max_delay:     32.0,
  multiplier:    1.3,
  retry_codes:   ["UNAVAILABLE"]
}
call_options = { timeout: timeout, retry_policy: retry_policy }

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", call_options: call_options

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #fields

    def fields(types) -> Fields

Creates a configuration object ([Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)")) that may be provided to
queries or used to create STRUCT objects. (The STRUCT will be
represented by the [Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") class.) See [Client#execute](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Client#Google__Cloud__Spanner__Client_execute_instance_ "Google::Cloud::Spanner::Client#execute (method)") and/or
[Fields#struct](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields#Google__Cloud__Spanner__Fields_struct_instance_ "Google::Cloud::Spanner::Fields#struct (method)").


For more information, see [Data Types - Constructing a
STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).

<br />

See [Data Types - Constructing a
STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).
**Parameter**

- **types** (Array, Hash) ---

  Accepts an array or hash types.

  Arrays can contain just the type value, or a sub-array of the
  field's name and type value. Hash keys must contain the field name
  as a `Symbol` or `String`, or the field position as an `Integer`.
  Hash values must contain the type value. If a Hash is used the
  fields will be created using the same order as the Hash keys.

  Supported type values include:
  - `:BOOL`
  - `:BYTES`
  - `:DATE`
  - `:FLOAT64`
  - `:FLOAT32`
  - `:NUMERIC`
  - `:INT64`
  - `:STRING`
  - `:TIMESTAMP`
  - `:UUID`
  - `Array` - Lists are specified by providing the type code in an array. For example, an array of integers are specified as `[:INT64]`.
  - [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") - Nested Structs are specified by providing a Fields object.
**Returns**

- ([Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields)) --- The fields of the given types.
**Examples**

Create a STRUCT value with named fields using Fields object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  named_type = snp.fields(
    { id: :INT64, name: :STRING, active: :BOOL }
  )
  named_data = named_type.struct(
    { id: 42, name: nil, active: false }
  )
end
```

Create a STRUCT value with anonymous field names:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  anon_type = snp.fields [:INT64, :STRING, :BOOL]
  anon_data = anon_type.struct [42, nil, false]
end
```

Create a STRUCT value with duplicate field names:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  dup_type = snp.fields [[:x, :INT64], [:x, :STRING], [:x, :BOOL]]
  dup_data = dup_type.struct [42, nil, false]
end
```

### #query

    def query(sql, params: nil, types: nil, query_options: nil, request_options: nil, call_options: nil, directed_read_options: nil) -> Google::Cloud::Spanner::Results

**Alias Of** : [#execute_query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_query_instance_) Executes a SQL query.

The following settings can be provided:

- `:exclude_replicas` (Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.
- `:include_replicas` (Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
**Parameters**

- **sql** (String) --- The SQL query string. See [Query
  syntax](https://cloud.google.com/spanner/docs/query-syntax).


  The SQL query string can contain parameter placeholders. A parameter
  placeholder consists of "@" followed by the parameter name.
  Parameter names consist of any combination of letters, numbers, and
  underscores.
- **params** (Hash) *(defaults to: nil)* --- SQL parameters for the query string. The parameter placeholders, minus the "@", are the the hash keys, and the literal values are the hash values. If the query string contains something like "WHERE id \> @msg_id", then the params must contain something like `:msg_id => 1`.


  Ruby types are mapped to Spanner types as follows:

  \| Spanner \| Ruby \| Notes \|
  \|---\|---\|---\|
  \| `BOOL` \| `true`/`false` \| \|
  \| `INT64` \| `Integer` \| \|
  \| `FLOAT64` \| `Float` \| \|
  \| `FLOAT32` \| `Float` \| \|
  \| `NUMERIC` \| `BigDecimal` \| \|
  \| `STRING` \| `String` \| \|
  \| `UUID` \| `String` \| \|
  \| `DATE` \| `Date` \| \|
  \| `TIMESTAMP` \| `Time`, `DateTime` \| \|
  \| `BYTES` \| `File`, `IO`, `StringIO`, or similar \| \|
  \| `ARRAY` \| `Array` \| Nested arrays are not supported. \|
  \| `STRUCT` \| `Hash`, [Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") \| \|

  See [Data
  types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).

  See [Data Types - Constructing a
  STRUCT](https://cloud.google.com/spanner/docs/data-types#constructing-a-struct).
- **types** (Hash) *(defaults to: nil)* --- Types of the SQL parameters in `params`. It is not always possible for Cloud Spanner to infer the right SQL type from a value in `params`. In these cases, the `types` hash must be used to specify the SQL type for these values.


  The keys of the hash should be query string parameter placeholders,
  minus the "@". The values of the hash should be Cloud Spanner type
  codes from the following list:
  - `:BOOL`
  - `:BYTES`
  - `:DATE`
  - `:FLOAT64`
  - `:FLOAT32`
  - `:NUMERIC`
  - `:INT64`
  - `:STRING`
  - `:TIMESTAMP`
  - `:UUID`
  - `Array` - Lists are specified by providing the type code in an array. For example, an array of integers are specified as `[:INT64]`.
  - [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") - Types for STRUCT values (`Hash`/[Data](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data "Google::Cloud::Spanner::Data (class)") objects) are specified using a [Fields](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields "Google::Cloud::Spanner::Fields (class)") object.

  Types are optional.
- **query_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  query options for executing SQL query. Query options are optional.
  The following settings can be provided:
  - `:optimizer_version` (String) The version of optimizer to use. Empty to use database default. "latest" to use the latest available optimizer version.
  - `:optimizer_statistics_package` (String) Statistics package to use. Empty to use the database default.
- **request_options** (Hash) *(defaults to: nil)* ---

  Common request options.
  - `:priority` (Symbol) The relative priority for requests. The priority acts as a hint to the Cloud Spanner scheduler and does not guarantee priority or order of execution. Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`, `:PRIORITY_HIGH`. If priority not set then default is `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
  - `:tag` (String) A per-request tag which can be applied to queries or reads, used for statistics collection. Tag must be a valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
- **call_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  call options, e.g., timeout, retries, etc. Call options are
  optional. The following settings can be provided:
  - `:timeout` (Numeric) A numeric value of custom timeout in seconds that overrides the default setting.
  - `:retry_policy` (Hash) A hash of values that overrides the default setting of retry policy with the following keys:
    - `:initial_delay` (`Numeric`) - The initial delay in seconds.
    - `:max_delay` (`Numeric`) - The max delay in seconds.
    - `:multiplier` (`Numeric`) - The incremental backoff multiplier.
    - `:retry_codes` (`Array<String>`) - The error codes that should trigger a retry.
- **directed_read_options** (Hash) *(defaults to: nil)* --- Client options used to set the directed_read_options for all ReadRequests and ExecuteSqlRequests that indicates which replicas or regions should be used for non-transactional reads or queries. Will represent [`Google::Cloud::Spanner::V1::DirectedReadOptions`](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-DirectedReadOptions)
**Returns**

- ([Google::Cloud::Spanner::Results](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Results)) --- The results of the query execution.
**Examples**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users"

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query parameters:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query "SELECT * FROM users " \
                        "WHERE active = @active",
                        params: { active: true }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query with a SQL STRUCT query parameter as a Hash:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_hash = { id: 1, name: "Charlie", active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Specify the SQL STRUCT type using Fields object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
   user_hash = { id: 1, name: nil, active: false }

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_hash },
    types: { user_struct: user_type }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Or, query with a SQL STRUCT as a typed Data object:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
   user_type = snp.fields id: :INT64, name: :STRING, active: :BOOL
user_data = user_type.struct id: 1, name: nil, active: false

  results = snp.execute_query(
    "SELECT * FROM users WHERE " \
    "ID = @user_struct.id " \
    "AND name = @user_struct.name " \
    "AND active = @user_struct.active",
    params: { user_struct: user_data }
  )

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using query options:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", query_options: {
      optimizer_version: "1",
      optimizer_statistics_package: "auto_20191128_14_47_22UTC"
    }

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

Query using custom timeout and retry policy:

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

timeout = 30.0
retry_policy = {
  initial_delay: 0.25,
  max_delay:     32.0,
  multiplier:    1.3,
  retry_codes:   ["UNAVAILABLE"]
}
call_options = { timeout: timeout, retry_policy: retry_policy }

db.snapshot do |snp|
  results = snp.execute_query \
    "SELECT * FROM users", call_options: call_options

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #range

    def range(beginning, ending, exclude_begin: false, exclude_end: false) -> Google::Cloud::Spanner::Range

Creates a Cloud Spanner Range. This can be used in place of a Ruby
Range when needing to exclude the beginning value.
**Parameters**

- **beginning** (Object) --- The object that defines the beginning of the range.
- **ending** (Object) --- The object that defines the end of the range.
- **exclude_begin** (Boolean) *(defaults to: false)* --- Determines if the range excludes its beginning value. Default is `false`.
- **exclude_end** (Boolean) *(defaults to: false)* --- Determines if the range excludes its ending value. Default is `false`.
**Returns**

- ([Google::Cloud::Spanner::Range](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Range)) --- The new Range instance.
**Example**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  key_range = db.range 1, 100
  results = snp.read "users", [:id, :name], keys: key_range

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #read

    def read(table, columns, keys: nil, index: nil, limit: nil, request_options: nil, call_options: nil, directed_read_options: nil) -> Google::Cloud::Spanner::Results

Read rows from a database table, as a simple alternative to
[#execute_query](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Snapshot#Google__Cloud__Spanner__Snapshot_execute_query_instance_ "Google::Cloud::Spanner::Snapshot#execute_query (method)").

The following settings can be provided:

- `:exclude_replicas` (Hash) Exclude_replicas indicates what replicas should be excluded from serving requests. Spanner will not route requests to the replicas in this list.
- `:include_replicas` (Hash) Include_replicas indicates the order of replicas to process the request. If auto_failover_disabled is set to true and all replicas are exhausted without finding a healthy replica, Spanner will wait for a replica in the list to become available, requests may fail due to DEADLINE_EXCEEDED errors.
**Parameters**

- **table** (String) --- The name of the table in the database to be read.
- **columns** (Array\<String, Symbol\>) --- The columns of table to be returned for each row matching this request.
- **keys** (Object, Array\<Object\>) *(defaults to: nil)* --- A single, or list of keys or key ranges to match returned data to. Values should have exactly as many elements as there are columns in the primary key.
- **index** (String) *(defaults to: nil)* --- The name of an index to use instead of the table's primary key when interpreting `id` and sorting result rows. Optional.
- **limit** (Integer) *(defaults to: nil)* --- If greater than zero, no more than this number of rows will be returned. The default is no limit.
- **request_options** (Hash) *(defaults to: nil)* ---

  Common request options.
  - `:priority` (Symbol) The relative priority for requests. The priority acts as a hint to the Cloud Spanner scheduler and does not guarantee priority or order of execution. Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`, `:PRIORITY_HIGH`. If priority not set then default is `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
  - `:tag` (String) A per-request tag which can be applied to queries or reads, used for statistics collection. Tag must be a valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2 and 64 characters in length.
- **call_options** (Hash) *(defaults to: nil)* ---

  A hash of values to specify the custom
  call options, e.g., timeout, retries, etc. Call options are
  optional. The following settings can be provided:
  - `:timeout` (Numeric) A numeric value of custom timeout in seconds that overrides the default setting.
  - `:retry_policy` (Hash) A hash of values that overrides the default setting of retry policy with the following keys:
    - `:initial_delay` (`Numeric`) - The initial delay in seconds.
    - `:max_delay` (`Numeric`) - The max delay in seconds.
    - `:multiplier` (`Numeric`) - The incremental backoff multiplier.
    - `:retry_codes` (`Array<String>`) - The error codes that should trigger a retry.
- **directed_read_options** (Hash) *(defaults to: nil)* --- Client options used to set the directed_read_options for all ReadRequests and ExecuteSqlRequests that indicates which replicas or regions should be used for non-transactional reads or queries. Will represent [`Google::Cloud::Spanner::V1::DirectedReadOptions`](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-DirectedReadOptions)
**Returns**

- ([Google::Cloud::Spanner::Results](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Results)) --- The results of the read operation.
**Example**

```ruby
require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"

db.snapshot do |snp|
  results = snp.read "users", [:id, :name]

  results.rows.each do |row|
    puts "User #{row[:id]} is #{row[:name]}"
  end
end
```

### #timestamp

    def timestamp() -> Time

The read timestamp chosen for snapshots.
**Returns**

- (Time) --- The chosen timestamp.

### #transaction_id

    def transaction_id() -> String

Identifier of the transaction results were run in.
**Returns**

- (String) --- The transaction id.