Jump to: navigation, search

PostgreSQL LEFT

From w3cyberlearnings

Contents

Postgresql left

This function returns a substring based from the left side which specifies by the length. When the length is negative, return all but last n characters.

Syntax left

left(string, length)

Example 1

postgres=# SELECT left('apple',2);
 left 
------
 ap
(1 row)

Example 2

postgres=# SELECT left('apple',-2);
 left 
------
 app
(1 row)

Example 3

postgres=# SELECT name,left(name,2)
postgres-# FROM employee;
  name  | left 
--------+------
 John   | Jo
 Week   | We
 Christ | Ch
(3 rows)

Related Links


Navigation
Web
SQL
MISC
References