- Categories:
Semi-structured Data Functions (Array/Object)
OBJECT_PICKΒΆ
Returns a new OBJECT containing some of the key-value pairs from an existing object.
To identify the key-value pairs to include in the new object, pass in the keys as arguments, or pass in an array containing the keys.
If a specified key is not present in the input object, the key is ignored.
SyntaxΒΆ
OBJECT_PICK( <object>, <key1> [, <key2>, ... ] )
OBJECT_PICK( <object>, <array> )
ArgumentsΒΆ
object
The input object.
key1
,key2
One or more keys identifying the key-value pairs that should be included in the returned object.
array
Array of keys identifying the key-value pairs that should be included in the returned object.
ReturnsΒΆ
Returns a new OBJECT containing the specified key-value pairs.
ExamplesΒΆ
The following example calls OBJECT_PICK to create a new object that contains two of the three key-value pairs from an existing object:
SELECT OBJECT_PICK( OBJECT_CONSTRUCT( 'a', 1, 'b', 2, 'c', 3 ), 'a', 'b' ) AS new_object; +------------+ | NEW_OBJECT | |------------| | { | | "a": 1, | | "b": 2 | | } | +------------+
In the example above, the keys are passed as arguments to OBJECT_PICK. You can also use an array to specify the keys, as shown below:
SELECT OBJECT_PICK( OBJECT_CONSTRUCT( 'a', 1, 'b', 2, 'c', 3 ), ARRAY_CONSTRUCT('a', 'b') ) AS new_object; +------------+ | NEW_OBJECT | |------------| | { | | "a": 1, | | "b": 2 | | } | +------------+