OBJECT_PICK
functionsupportedCore SQL functionsReturns 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
supportedpartialnot supportednot scored
OBJECT_PICK( <object>, <key1> [, <key2>, ... ] )
OBJECT_PICK( <object>, <array> )
Parameters
| Name | Required | Description |
|---|---|---|
object | required | The input object. |
key1, key2 | required | One or more keys identifying the key-value pairs that should be included in the returned object. |
array | required | 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.
Usage notes
- For structured OBJECTs:
- For the arguments that are keys, you must specify constants.
- You can’t pass in an ARRAY of keys as the second argument. You must specify each key as a separate argument.
- The function returns a structured OBJECT value. The type of the OBJECT value includes the keys in the order in which they are specified. For example, suppose that you select the state and city keys in that order: Copy code SELECT OBJECT_PICK( {'city':'San Mateo','state':'CA','zip_code':94402}::OBJECT(city VARCHAR,state VARCHAR,zip_code DOUBLE), 'state', 'city') AS new_object, SYSTEM$TYPEOF(new_object); The function returns an OBJECT value of the type OBJECT(state VARCHAR, city VARCHAR). +-----------------------+------------------------------------------+ | NEW_OBJECT | SYSTEM$TYPEOF(NEW_OBJECT) | |-----------------------+------------------------------------------| | { | OBJECT(state VARCHAR, city VARCHAR)[LOB] | | "state": "CA", | | | "city": "San Mateo" | | | } | | +-----------------------+------------------------------------------+