Reference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Data.
Data
Represents a row in a result from Cloud Spanner. Provides access to data
in a hash-like structure. Values can be retrieved by name (String), or
in cases in which values are unnamed, by zero-based index position
(Integer).
Inherits
Object
Example
require"google/cloud/spanner"spanner=Google::Cloud::Spanner.newdb=spanner.client"my-instance","my-database"results=db.execute_query"SELECT * FROM users"results.rows.eachdo|row|puts"User#{row[:id]}is#{row[:name]}"end
Methods
#[]
def[](key)->Object,nil
Returns the value object for the provided name (String) or index
(Integer). Do not pass a name to this method if the data has more than
one member with the same name.
Parameter
key(String, Integer) — The name (String) or zero-based index
position (Integer) of the value.
Returns
(Object, nil) — The value, or nil if no value is found.
Returns the configuration object (Fields) of the names and types of
the data.
Returns
(Array<Array>) — An array containing name and value pairs.
#keys
defkeys()->Array<(String,Integer)>
Returns the names of values, or in cases in which values are unnamed,
the zero-based index position of values.
Returns
(Array<(String,Integer)>) — An array containing the names
(String) or position (Integer) for the corresponding values of the
data.
#pairs
defpairs()->Array<Array>
Returns the names or positions and their corresponding values as an
array of arrays.
Returns
(Array<Array>) — An array containing name/position and value
pairs.
#to_a
defto_a(skip_dup_check:nil)->Array<Object>
Returns the values as an array. This method will raiseDuplicateNameErrorif nested data has more than one member with the
same name, unlessskip_dup_checkis set totrue, in which case it
will lose values.
Parameter
skip_dup_check(Boolean)(defaults to: nil)— Skip the check for whether nested data
contains duplicate names, which will improve performance. When
skipped, the nested hash may lose values. Default isfalse.
Optional.
Returns
(Array<Object>) — An array containing the values of the data.
Returns the names or indexes and corresponding values of the data as a
hash. This method will raiseDuplicateNameErrorif the data has more
than one member with the same name, unlessskip_dup_checkis set totrue, in which case it will lose values.
Parameter
skip_dup_check(Boolean)(defaults to: nil)— Skip the check for whether the data
contains duplicate names, which will improve performance. When
skipped, the returned hash may lose values. Default isfalse.
Optional.
Returns
(Hash<(String,Integer)=>Object>) — A hash containing the names
or indexes and corresponding values.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Spanner API - Class Google::Cloud::Spanner::Data (v2.27.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.27.0 (latest)](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Data)\n- [2.26.0](/ruby/docs/reference/google-cloud-spanner/2.26.0/Google-Cloud-Spanner-Data)\n- [2.25.0](/ruby/docs/reference/google-cloud-spanner/2.25.0/Google-Cloud-Spanner-Data)\n- [2.24.0](/ruby/docs/reference/google-cloud-spanner/2.24.0/Google-Cloud-Spanner-Data)\n- [2.23.0](/ruby/docs/reference/google-cloud-spanner/2.23.0/Google-Cloud-Spanner-Data)\n- [2.22.0](/ruby/docs/reference/google-cloud-spanner/2.22.0/Google-Cloud-Spanner-Data)\n- [2.21.0](/ruby/docs/reference/google-cloud-spanner/2.21.0/Google-Cloud-Spanner-Data)\n- [2.20.0](/ruby/docs/reference/google-cloud-spanner/2.20.0/Google-Cloud-Spanner-Data)\n- [2.19.1](/ruby/docs/reference/google-cloud-spanner/2.19.1/Google-Cloud-Spanner-Data)\n- [2.18.1](/ruby/docs/reference/google-cloud-spanner/2.18.1/Google-Cloud-Spanner-Data)\n- [2.17.0](/ruby/docs/reference/google-cloud-spanner/2.17.0/Google-Cloud-Spanner-Data)\n- [2.16.1](/ruby/docs/reference/google-cloud-spanner/2.16.1/Google-Cloud-Spanner-Data)\n- [2.15.0](/ruby/docs/reference/google-cloud-spanner/2.15.0/Google-Cloud-Spanner-Data)\n- [2.14.0](/ruby/docs/reference/google-cloud-spanner/2.14.0/Google-Cloud-Spanner-Data)\n- [2.13.0](/ruby/docs/reference/google-cloud-spanner/2.13.0/Google-Cloud-Spanner-Data)\n- [2.12.1](/ruby/docs/reference/google-cloud-spanner/2.12.1/Google-Cloud-Spanner-Data)\n- [2.11.0](/ruby/docs/reference/google-cloud-spanner/2.11.0/Google-Cloud-Spanner-Data) \nReference documentation and code samples for the Cloud Spanner API class Google::Cloud::Spanner::Data.\n\nData\n----\n\nRepresents a row in a result from Cloud Spanner. Provides access to data\nin a hash-like structure. Values can be retrieved by name (String), or\nin cases in which values are unnamed, by zero-based index position\n(Integer). \n\nInherits\n--------\n\n- Object\n\nExample\n-------\n\n```ruby\nrequire \"google/cloud/spanner\"\n\nspanner = Google::Cloud::Spanner.new\n\ndb = spanner.client \"my-instance\", \"my-database\"\n\nresults = db.execute_query \"SELECT * FROM users\"\n\nresults.rows.each do |row|\n puts \"User #{row[:id]} is #{row[:name]}\"\nend\n```\n\nMethods\n-------\n\n### #\\[\\]\n\n def [](key) -\u003e Object, nil\n\nReturns the value object for the provided name (String) or index\n(Integer). Do not pass a name to this method if the data has more than\none member with the same name. \n**Parameter**\n\n- **key** (String, Integer) --- The name (String) or zero-based index position (Integer) of the value. \n**Returns**\n\n- (Object, nil) --- The value, or nil if no value is found. \n**Raises**\n\n- ([Google::Cloud::Spanner::DuplicateNameError](./Google-Cloud-Spanner-DuplicateNameError)) --- if the data contains duplicate names.\n\n### #fields\n\n def fields() -\u003e Array\u003cArray\u003e\n\nReturns the configuration object ([Fields](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Fields \"Google::Cloud::Spanner::Fields (class)\")) of the names and types of\nthe data. \n**Returns**\n\n- (Array\\\u003cArray\\\u003e) --- An array containing name and value pairs.\n\n### #keys\n\n def keys() -\u003e Array\u003c(String,Integer)\u003e\n\nReturns the names of values, or in cases in which values are unnamed,\nthe zero-based index position of values. \n**Returns**\n\n- (Array\\\u003c(String,Integer)\\\u003e) --- An array containing the names (String) or position (Integer) for the corresponding values of the data.\n\n### #pairs\n\n def pairs() -\u003e Array\u003cArray\u003e\n\nReturns the names or positions and their corresponding values as an\narray of arrays. \n**Returns**\n\n- (Array\\\u003cArray\\\u003e) --- An array containing name/position and value pairs.\n\n### #to_a\n\n def to_a(skip_dup_check: nil) -\u003e Array\u003cObject\u003e\n\nReturns the values as an array. This method will raise\n[DuplicateNameError](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-DuplicateNameError \"Google::Cloud::Spanner::DuplicateNameError (class)\") if nested data has more than one member with the\nsame name, unless `skip_dup_check` is set to `true`, in which case it\nwill lose values. \n**Parameter**\n\n- **skip_dup_check** (Boolean) *(defaults to: nil)* --- Skip the check for whether nested data contains duplicate names, which will improve performance. When skipped, the nested hash may lose values. Default is `false`. Optional. \n**Returns**\n\n- (Array\\\u003cObject\\\u003e) --- An array containing the values of the data. \n**Raises**\n\n- ([Google::Cloud::Spanner::DuplicateNameError](./Google-Cloud-Spanner-DuplicateNameError)) --- if nested data contains duplicate names.\n\n### #to_h\n\n def to_h(skip_dup_check: nil) -\u003e Hash\u003c(String,Integer)=\u003eObject\u003e\n\nReturns the names or indexes and corresponding values of the data as a\nhash. This method will raise [DuplicateNameError](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-DuplicateNameError \"Google::Cloud::Spanner::DuplicateNameError (class)\") if the data has more\nthan one member with the same name, unless `skip_dup_check` is set to\n`true`, in which case it will lose values. \n**Parameter**\n\n- **skip_dup_check** (Boolean) *(defaults to: nil)* --- Skip the check for whether the data contains duplicate names, which will improve performance. When skipped, the returned hash may lose values. Default is `false`. Optional. \n**Returns**\n\n- (Hash\\\u003c(String,Integer)=\\\u003eObject\\\u003e) --- A hash containing the names or indexes and corresponding values. \n**Raises**\n\n- ([Google::Cloud::Spanner::DuplicateNameError](./Google-Cloud-Spanner-DuplicateNameError)) --- if the data contains duplicate names.\n\n### #types\n\n def types() -\u003e Array\u003cSymbol\u003e\n\nReturns the types of the data.\n\n\n\u003cbr /\u003e\n\nSee [Data\ntypes](https://cloud.google.com/spanner/docs/data-definition-language#data_types). \n**Returns**\n\n- (Array\\\u003cSymbol\\\u003e) --- An array containing the types of the values.\n\n### #values\n\n def values() -\u003e Array\u003cObject\u003e\n\nReturns the values of the data. \n**Returns**\n\n- (Array\\\u003cObject\\\u003e) --- An array containing the values."]]