snowflake.snowpark.functions.lit

snowflake.snowpark.functions.lit(literal: Union[None, bool, int, float, str, bytearray, Decimal, date, datetime, time, bytes, NaTType, float64, list, tuple, dict]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L291-L315)

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
语言: 中文