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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

starts_with(string, prefix)  |  string ^@ prefix

Parameters

ParameterDescription
string The input text.
prefix The prefix to test.

Return value

boolean.

Examples

Test a prefix
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.

Filter rows
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

VersionChange
PostgreSQL 11Added

Was this page helpful?