PostgreSQL SUBSTR
From w3cyberlearnings
Contents |
Postgresql substr
This function returns a substring from a given string. It is similar to SUBSTRING() functions.
Syntax substr
- string is a main string to extract from.
- start is the start position.
- length is the length of the substring to be extracted.
substr(string, start, length)
Example 1
test2=# SELECT substr('abcd',2,2); substr -------- bc (1 row) test2=# SELECT substr('excellent',2,5); substr -------- xcell (1 row)
Example 2
test2=# SELECT user_firstname, test2-# substr(user_firstname,1,1), test2-# user_lastname, test2-# substr(user_lastname,1,1) test2-# FROM profile; user_firstname | substr | user_lastname | substr ----------------+--------+---------------+-------- Jim | J | Jkim | J king | k | queen | q Jammi | J | weeks | w Bob | B | Mark | M (4 rows)