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

snowflake.snowpark.functions.locate¶

snowflake.snowpark.functions.locate(expr1: str, expr2: Union[Column, str], start_pos: int = 1) → Column[source]¶

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