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

snowflake.snowpark.functions.to_array¶

snowflake.snowpark.functions.to_array(e: Union[Column, str]) → Column[source]¶

Converts any value to an ARRAY value or NULL (if input is NULL).

Example:

>>> df = session.create_dataframe([1, 2, 3, 4], schema=['a'])
>>> df.select(to_array(col('a')).as_('ans')).collect()
[Row(ANS='[\n  1\n]'), Row(ANS='[\n  2\n]'), Row(ANS='[\n  3\n]'), Row(ANS='[\n  4\n]')]


>>> from snowflake.snowpark import Row
>>> df = session.create_dataframe([Row(a=[1, 2, 3]), Row(a=None)])
>>> df.select(to_array(col('a')).as_('ans')).collect()
[Row(ANS='[\n  1,\n  2,\n  3\n]'), Row(ANS=None)]
Copy