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.26.0/snowpark-python/src/snowflake/snowpark/functions.py#L10006-L10033)¶
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.
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 | -----------