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

snowflake.snowpark.functions.object_insert¶

snowflake.snowpark.functions.object_insert(obj: ColumnOrName, key: ColumnOrName, value: ColumnOrName, update_flag: ColumnOrName | None = None) → Column[source]¶

Returns an object consisting of the input object with a new key-value pair inserted (or an existing key updated with a new value).

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_insert(col("obj"), lit("key"), lit("v")).alias("result")).show()
--------------------
|"RESULT"          |
--------------------
|{                 |
|  "age": 21,      |
|  "key": "v",     |
|  "name": "Joe",  |
|  "zip": 21021    |
|}                 |
|{                 |
|  "age": 26,      |
|  "key": "v",     |
|  "name": "Jay",  |
|  "zip": 94021    |
|}                 |
--------------------
Copy