postgresqlHow can I use PostgreSQL substring functions?
PostgreSQL substring functions allow you to extract a substring from a string. The most commonly used substring functions are substr
, left
, right
, and substring
.
Example code
SELECT substr('PostgreSQL', 6);
Output example
SQL
The substr
function takes two parameters: the string and the start position. It returns the substring starting from the start position to the end of the string.
The left
function takes two parameters: the string and the number of characters to extract. It returns the leftmost substring of the specified length.
Example code
SELECT left('PostgreSQL', 4);
Output example
Post
The right
function takes two parameters: the string and the number of characters to extract. It returns the rightmost substring of the specified length.
Example code
SELECT right('PostgreSQL', 3);
Output example
SQL
The substring
function takes three parameters: the string, the start position, and the number of characters to extract. It returns the substring starting from the start position with the specified length.
Example code
SELECT substring('PostgreSQL', 2, 5);
Output example
ostG
For more information on PostgreSQL substring functions, see the PostgreSQL Documentation.
More of Postgresql
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I parse XML data using PostgreSQL?
- How can I use PostgreSQL and ZFS snapshots together?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can Zalando use PostgreSQL to improve its software development?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How can I use PostgreSQL XOR to compare two values?
- How do I set the PostgreSQL work_mem parameter?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL XML functions to manipulate XML data?
See more codes...