PostgreSQL 18 reference · String Functions
PostgreSQL STARTS_WITH() Function
Return true if a string starts with a given prefix. The ^@ operator does the same and can use an index.
PostgreSQL 18 Since 11
Syntax
starts_with(string, prefix) | string ^@ prefix
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
prefix |
The prefix to test. |
Return value
boolean.
Examples
SELECT starts_with('https://readycamel.com', 'https') AS a, 'Ada' ^@ 'Al' AS b;
Output
a | b ---+--- t | f (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT name FROM products WHERE starts_with(name, 'S');
Output
name ------------------- SQL for Beginners Standing Desk Mat (2 rows)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 11 | Added |
Related
POSITION()· Return the 1-based position of a substring inside a string, or 0 if it isn't found. strpos() takes the arguments in the other order.ILIKE· Match a string against a LIKE pattern ignoring case: % matches any text and _ one character. ~~* is the operator form.- SQL String Functions · tutorial