snowflake.snowpark.functions.substring¶
- snowflake.snowpark.functions.substring(str: Union[Column, str], pos: Union[Column, int], len: Optional[Union[Column, int]] = None) Column [source]¶
Returns the portion of the string or binary value str, starting from the character/byte specified by pos, with limited length. The length should be greater than or equal to zero. If the length is a negative number, the function returns an empty string.
Note
For
pos
, 1 is the first character of the string in Snowflake database.substr()
is an alias ofsubstring()
.- Example 1::
>>> df = session.create_dataframe( ... ["abc", "def"], ... schema=["S"], ... ) >>> df.select(substring(col("S"), 1, 1)).collect() [Row(SUBSTRING("S", 1, 1)='a'), Row(SUBSTRING("S", 1, 1)='d')]
- Example 2::
>>> df = session.create_dataframe( ... ["abc", "def"], ... schema=["S"], ... ) >>> df.select(substring(col("S"), 2)).collect() [Row(SUBSTRING("S", 2)='bc'), Row(SUBSTRING("S", 2)='ef')]