position
position(haystack: string, needle: string, [start: int64]?) -> int64
Returns the zero-based index of the first occurrence of needle inside haystack, or -1 when there is no match. Both string arguments may be null, which yields a null int64. An optional third argument is a starting offset; when it is null the result is null, and when it is negative it is treated as zero for constant-folded calls. If the start offset is at or beyond the end of the haystack, the function returns -1 without searching.
Domain
This is a scalar function (calculates a single output value for a single input row).
Categories
Examples
make_col err_pos: position(log_line, "ERROR")
Finds the zero-based index of the first ERROR substring inside each log line, or -1 when absent.
make_col colon_after: position(log_line, ":", 5)
Skips the first five characters before searching for the first colon, illustrating the optional start offset.
Updated 18 days ago