You are viewing documentation about an older version (1.4.0). View latest version

snowflake.snowpark.functions.object_pick

snowflake.snowpark.functions.object_pick(obj: ColumnOrName, key1: ColumnOrName, *keys: ColumnOrName) Column[source]

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.

Example::
>>> from snowflake.snowpark.functions import lit
>>> df = session.sql(
...     "select object_construct(a,b,c,d,e,f) as obj, k, v from "
...     "values('age', 21, 'zip', 21021, 'name', 'Joe', 'age', 0),"
...     "('age', 26, 'zip', 94021, 'name', 'Jay', 'age', 0) as T(a,b,c,d,e,f,k,v)"
... )
>>> df.select(object_pick(col("obj"), col("k"), lit("name")).alias("result")).show()
-------------------
|"RESULT"         |
-------------------
|{                |
|  "age": 21,     |
|  "name": "Joe"  |
|}                |
|{                |
|  "age": 26,     |
|  "name": "Jay"  |
|}                |
-------------------
Copy