POSITION is a standard SQL string-search function. It scans a character expression (the source string) from left to right and returns the integer position at which a specified substring first appears. If the substring is not found, it returns 0 in most databases (or NULL in some). The count starts at 1, not 0. The operation is case-sensitive in case-sensitive collations. Collation or locale settings may influence the comparison rules. Some systems expose POSITION only for compatibility and prefer dialect-specific synonyms such as STRPOS (PostgreSQL), LOCATE (MySQL), CHARINDEX (SQL Server), or INSTR (Oracle, SQLite). POSITION does not modify data, can be used in SELECT, WHERE, ORDER BY, or JOIN clauses, and works on CHAR, VARCHAR, TEXT, and compatible character types. It is deterministic and free of side effects, making it safe inside indexed expressions or deterministic functions. The function typically requires two arguments, but certain dialects offer an optional starting position to begin the search.
substring
(STRING) - The sequence of characters to locate.string
(STRING) - The character expression to search within.start_index
(INTEGER, optional, MySQL only) - 1-based position at which to start searching.STRPOS, LOCATE, CHARINDEX, INSTR, SUBSTRING, LIKE, REGEXP
SQL-92 standard
The search begins at position 1 by default. Some dialects let you supply a start_index argument.
Yes. Most modern databases store text in UTF-8 or UTF-16, and POSITION operates on character positions, not bytes.
Wrap both operands in LOWER or set a case-insensitive collation: `POSITION(LOWER('abc') IN LOWER(colname))`.
POSITION returns NULL because any operation involving NULL results in NULL.