PostgreSQL 18 reference · String Functions

PostgreSQL LEFT() Function

Return the first n characters of a string. A negative n returns all but the last |n| characters.

PostgreSQL 18 Since 9.1

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

Syntax

left(string, n)

Parameters

ParameterDescription
string The input text.
n How many characters to keep; negative drops from the end.

Return value

Text.

Examples

From the left
SELECT left('ReadyCamel', 5) AS a, left('ReadyCamel', -5) AS b;

Output

   a   |   b
-------+-------
 Ready | Ready
(1 row)

Run this on your computer — see “Get Started” for setup.

Initials
SELECT name, left(name, 1) || '.' AS initial
FROM customers
LIMIT 3;

Output

     name     | initial
--------------+---------
 Ada Lovelace | A.
 Alan Turing  | A.
 Grace Hopper | G.
(3 rows)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 9.1Added

In other languages

Was this page helpful?