starts_with()

A function determining whether a string starts with a particular prefix

starts_with() is a system function determining whether the provided string starts with the specified prefix.

starts_with() was added in PostgreSQL 11.

Usage

starts_with ( string text, prefix text ) → boolean

Note there is no corresponding ends_with() function.

Alternative

The following statement is functionally equivalent to starts_with() and works in PostgreSQL 10 and earlier:

SELECT TRUE WHERE string LIKE 'foo%'

Change history

Examples

Basic execution of starts_with():

postgres=# SELECT starts_with('foobar', 'foo');
 starts_with 
-------------
 t
(1 row)

starts_with() returns FALSE if the provided prefix does not match the string:

postgres=# SELECT starts_with('foobar', 'bar');
 starts_with 
-------------
 f
(1 row)

Categories

System function