snowflake.snowpark.functions.charindex¶

snowflake.snowpark.functions.charindex(target_expr: Union[Column, str], source_expr: Union[Column, str], position: Optional[Union[Column, int]] = None) → Column[source]¶

Searches for target_expr in source_expr and, if successful, returns the position (1-based) of the target_expr in source_expr.

Parameters:
  • target_expr – A string or binary expression representing the value to look for.

  • source_expr – A string or binary expression representing the value to search.

  • position – A number indication the position (1-based) from where to start the search. Defaults to None.

Examples::
>>> df = session.create_dataframe(["banana"], schema=['a'])
>>> df.select(charindex(lit("an"), df.a, 1).as_("result")).show()
------------
|"RESULT"  |
------------
|2         |
------------
Copy
>>> df.select(charindex(lit("an"), df.a, 3).as_("result")).show()
------------
|"RESULT"  |
------------
|4         |
------------
Copy