snowflake.snowpark.functions.locate

snowflake.snowpark.functions.locate(expr1: str, expr2: Union[Column, str], start_pos: int = 1) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.16.0/src/snowflake/snowpark/functions.py#L8442-L8466)

Searches for the first occurrence of the first argument in the second argument. If successful, returns the position (1-based) of the first argument in the second argument. Otherwise, return 0.

Note:

If the first argument is empty, this function always returns 1.
Copy

Example:

>>> df = session.create_dataframe([["find a needle in a haystack"],["nothing but hay in a haystack"]], schema=["expr"])
>>> df.select(locate("needle", col("expr")).alias("1-pos")).show()
-----------
|"1-pos"  |
-----------
|8        |
|0        |
-----------
Copy
语言: 中文