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

snowflake.snowpark.functions.charindex

snowflake.snowpark.functions.charindex(target_expr: ColumnOrName, source_expr: ColumnOrName, position: Column | int | None = 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