Reference documentation and code samples for the Cloud Spanner Client class KeyRange.
Represents a Cloud Spanner KeyRange.
Example:
use Google\Cloud\Spanner\SpannerClient;
$spanner = new SpannerClient();
// Create a KeyRange for all people named Bob, born in 1969.
$start = $spanner->date(new \DateTime('1969-01-01'));
$end = $spanner->date(new \DateTime('1969-12-31'));
$range = $spanner->keyRange([
'startType' => KeyRange::TYPE_CLOSED,
'start' => ['Bob', $start],
'endType' => KeyRange::TYPE_CLOSED,
'end' => ['Bob', $end]
]);
Namespace
Google \ Cloud \ Spanner
Methods
__construct
Create a KeyRange.
Parameters
Name
Description
options
array
Configuration Options.
↳ startType
string
Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness. Defaults toKeyRange::TYPE_OPEN.
↳ start
array
The key with which to start the range.
↳ endType
string
Either "open" or "closed". Use constants KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed correctness. Defaults toKeyRange::TYPE_OPEN.
↳ end
array
The key with which to end the range.
start
Get the range start.
Example:
$start = $range->start();
Returns
Type
Description
array|null
setStart
Set the range start.
Example:
$range->setStart(KeyRange::TYPE_OPEN, ['Bob']);
Parameters
Name
Description
type
string
Either "open" or "closed". Use constants
KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed
correctness.
start
array
The start of the key range.
Returns
Type
Description
void
end
Get the range end.
Example:
$end = $range->end();
Returns
Type
Description
array
setEnd
Set the range end.
Example:
$range->setEnd(KeyRange::TYPE_CLOSED, ['Jill']);
Parameters
Name
Description
type
string
Either "open" or "closed". Use constants
KeyRange::TYPE_OPEN and KeyRange::TYPE_CLOSED for guaranteed
correctness.
end
array
The end of the key range.
Returns
Type
Description
void
types
Get the start and end types
Example:
$types = $range->types();
Returns
Type
Description
array
An array containing `start` and `end` keys.
keyRangeObject
Returns an API-compliant representation of a KeyRange.
Returns
Type
Description
array
static::prefixMatch
Returns a key range that covers all keys where the first components match.
Equivalent to calling KeyRange::__construct() with closed type for start
and end, and the same key for the start and end.
[[["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 Client - Class KeyRange (1.104.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.104.0 (latest)](/php/docs/reference/cloud-spanner/latest/KeyRange)\n- [1.103.0](/php/docs/reference/cloud-spanner/1.103.0/KeyRange)\n- [1.102.0](/php/docs/reference/cloud-spanner/1.102.0/KeyRange)\n- [1.101.0](/php/docs/reference/cloud-spanner/1.101.0/KeyRange)\n- [1.100.0](/php/docs/reference/cloud-spanner/1.100.0/KeyRange)\n- [1.98.0](/php/docs/reference/cloud-spanner/1.98.0/KeyRange)\n- [1.97.0](/php/docs/reference/cloud-spanner/1.97.0/KeyRange)\n- [1.96.0](/php/docs/reference/cloud-spanner/1.96.0/KeyRange)\n- [1.95.0](/php/docs/reference/cloud-spanner/1.95.0/KeyRange)\n- [1.94.0](/php/docs/reference/cloud-spanner/1.94.0/KeyRange)\n- [1.93.1](/php/docs/reference/cloud-spanner/1.93.1/KeyRange)\n- [1.92.1](/php/docs/reference/cloud-spanner/1.92.1/KeyRange)\n- [1.91.0](/php/docs/reference/cloud-spanner/1.91.0/KeyRange)\n- [1.90.0](/php/docs/reference/cloud-spanner/1.90.0/KeyRange)\n- [1.89.0](/php/docs/reference/cloud-spanner/1.89.0/KeyRange)\n- [1.88.0](/php/docs/reference/cloud-spanner/1.88.0/KeyRange)\n- [1.87.0](/php/docs/reference/cloud-spanner/1.87.0/KeyRange)\n- [1.86.0](/php/docs/reference/cloud-spanner/1.86.0/KeyRange)\n- [1.85.0](/php/docs/reference/cloud-spanner/1.85.0/KeyRange)\n- [1.84.0](/php/docs/reference/cloud-spanner/1.84.0/KeyRange)\n- [1.83.0](/php/docs/reference/cloud-spanner/1.83.0/KeyRange)\n- [1.82.0](/php/docs/reference/cloud-spanner/1.82.0/KeyRange)\n- [1.81.0](/php/docs/reference/cloud-spanner/1.81.0/KeyRange)\n- [1.80.0](/php/docs/reference/cloud-spanner/1.80.0/KeyRange)\n- [1.79.0](/php/docs/reference/cloud-spanner/1.79.0/KeyRange)\n- [1.78.0](/php/docs/reference/cloud-spanner/1.78.0/KeyRange)\n- [1.77.0](/php/docs/reference/cloud-spanner/1.77.0/KeyRange)\n- [1.76.1](/php/docs/reference/cloud-spanner/1.76.1/KeyRange)\n- [1.68.0](/php/docs/reference/cloud-spanner/1.68.0/KeyRange)\n- [1.67.0](/php/docs/reference/cloud-spanner/1.67.0/KeyRange)\n- [1.66.0](/php/docs/reference/cloud-spanner/1.66.0/KeyRange)\n- [1.65.0](/php/docs/reference/cloud-spanner/1.65.0/KeyRange)\n- [1.64.0](/php/docs/reference/cloud-spanner/1.64.0/KeyRange)\n- [1.63.2](/php/docs/reference/cloud-spanner/1.63.2/KeyRange)\n- [1.62.1](/php/docs/reference/cloud-spanner/1.62.1/KeyRange)\n- [1.61.0](/php/docs/reference/cloud-spanner/1.61.0/KeyRange)\n- [1.60.0](/php/docs/reference/cloud-spanner/1.60.0/KeyRange)\n- [1.59.0](/php/docs/reference/cloud-spanner/1.59.0/KeyRange)\n- [1.58.4](/php/docs/reference/cloud-spanner/1.58.4/KeyRange)\n- [1.57.0](/php/docs/reference/cloud-spanner/1.57.0/KeyRange)\n- [1.56.0](/php/docs/reference/cloud-spanner/1.56.0/KeyRange)\n- [1.55.0](/php/docs/reference/cloud-spanner/1.55.0/KeyRange)\n- [1.54.2](/php/docs/reference/cloud-spanner/1.54.2/KeyRange) \nReference documentation and code samples for the Cloud Spanner Client class KeyRange.\n\nRepresents a Cloud Spanner KeyRange.\n\nExample: \n\n use Google\\Cloud\\Spanner\\SpannerClient;\n\n $spanner = new SpannerClient();\n\n // Create a KeyRange for all people named Bob, born in 1969.\n $start = $spanner-\u003edate(new \\DateTime('1969-01-01'));\n $end = $spanner-\u003edate(new \\DateTime('1969-12-31'));\n\n $range = $spanner-\u003ekeyRange([\n 'startType' =\u003e KeyRange::TYPE_CLOSED,\n 'start' =\u003e ['Bob', $start],\n 'endType' =\u003e KeyRange::TYPE_CLOSED,\n 'end' =\u003e ['Bob', $end]\n ]);\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Spanner\n\nMethods\n-------\n\n### __construct\n\nCreate a KeyRange.\n\n### start\n\nGet the range start.\n\nExample: \n\n $start = $range-\u003estart();\n\n### setStart\n\nSet the range start.\n\nExample: \n\n $range-\u003esetStart(KeyRange::TYPE_OPEN, ['Bob']);\n\n### end\n\nGet the range end.\n\nExample: \n\n $end = $range-\u003eend();\n\n### setEnd\n\nSet the range end.\n\nExample: \n\n $range-\u003esetEnd(KeyRange::TYPE_CLOSED, ['Jill']);\n\n### types\n\nGet the start and end types\n\nExample: \n\n $types = $range-\u003etypes();\n\n### keyRangeObject\n\nReturns an API-compliant representation of a KeyRange.\n\n### static::prefixMatch\n\nReturns a key range that covers all keys where the first components match.\n\nEquivalent to calling `KeyRange::__construct()` with closed type for start\nand end, and the same key for the start and end.\n\nExample: \n\n $range = KeyRange::prefixMatch($key);\n\n### static::fromArray\n\nCreate a KeyRange from an array created by [KeyRange::keyRangeObject()](/php/docs/reference/cloud-spanner/latest/KeyRange#_Google_Cloud_Spanner_KeyRange__keyRangeObject__).\n\nConstants\n---------\n\n### TYPE_OPEN\n\n Value: 'open'\n\n### TYPE_CLOSED\n\n Value: 'closed'"]]