left()

A function returning characters from the left of a string

left() is a system function returning the specified number characters from the left of the provided string.

left() was added in PostgreSQL 9.1.

Usage

left ( string text, n integer ) → text

If n is negative, returns all but the last n characters.

Change history

Examples

Basic usage example for left():

postgres=# SELECT left('foobar', 3);
 left 
------
 foo
(1 row)

Providing a negative value:

postgres=# SELECT left('foobarbaz', -3);
  left  
--------
 foobar
(1 row)

Usage with a non-Latin character set:

postgres=# SELECT left('ほげほげ', 2);
 left 
------
 ほげ
(1 row)

Categories

String manipulation, System function

See also

right(), ltrim()