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

snowflake.snowpark.functions.lit

snowflake.snowpark.functions.lit(literal: LiteralType) Column[source]

Creates a Column expression for a literal value. It supports basic Python data types, including int, float, str, bool, bytes, bytearray, datetime.time, datetime.date, datetime.datetime and decimal.Decimal. Also, it supports Python structured data types, including list, tuple and dict, but this container must be JSON serializable.

Example:

>>> import datetime
>>> columns = [lit(1), lit("1"), lit(1.0), lit(True), lit(b'snow'), lit(datetime.date(2023, 2, 2)), lit([1, 2]), lit({"snow": "flake"})]
>>> session.create_dataframe([[]]).select([c.as_(str(i)) for i, c in enumerate(columns)]).show()
---------------------------------------------------------------------------------------
|"0"  |"1"  |"2"  |"3"   |"4"                 |"5"         |"6"   |"7"                |
---------------------------------------------------------------------------------------
|1    |1    |1.0  |True  |bytearray(b'snow')  |2023-02-02  |[     |{                  |
|     |     |     |      |                    |            |  1,  |  "snow": "flake"  |
|     |     |     |      |                    |            |  2   |}                  |
|     |     |     |      |                    |            |]     |                   |
---------------------------------------------------------------------------------------
Copy