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
Syntax
left(string, n)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
n |
How many characters to keep; negative drops from the end. |
Return value
Text.
Examples
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.
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
| Version | Change |
|---|---|
| PostgreSQL 9.1 | Added |
In other languages
SUBSTR()· SQLite
Related
RIGHT()· Return the last n characters of a string. A negative n returns all but the first |n| characters.SUBSTRING()· Extract part of a string by 1-based position and length, or the part matching a regular expression.- SQL String Functions · tutorial