In today’s article, we will discuss the most used textual functions for String operations in PostgreSQL.
ASCII(): Returns numeric value of left-most character
|
1 |
select ASCII(‘faRUK’) |
BIT_LENGTH(): Returns length of argument in bits
|
1 |
select BIT_LENGTH(‘faRUK’) |
CHAR_LENGTH(): Returns number of characters in argument
|
1 |
select CHAR_LENGTH(‘FARUK’) |
CHARACTER_LENGTH(): A synonym for CHAR_LENGTH()
CONCAT_WS(): Returns concatenate with separator
|
1 |
select CONCAT_WS(‘,’,’FARUK ‘,’ ERDEM’) |
CONCAT(): Returns concatenated string
|
1 |
select CONCAT(‘FARUK ‘,’ ERDEM’) |
LEFT(): Returns the leftmost number of characters as specified
|
1 |
select LEFT(‘FARUK’,2) |
LENGTH(): Returns the length of a string in bytes
|
1 |
select LENGTH(‘FARUK ERDEM’) |
LOWER(): Returns the argument in lowercase
|
1 |
select lower(‘FARUK’) |
LTRIM(): Removes leading spaces
|
1 |
select LTRIM(‘ FARUK’) |
REPEAT(): Repeats a string the specified number of times
|
1 |
select REPEAT(‘PostgreSQL’,2) |
REPLACE(): Replaces occurrences of a specified string
|
1 |
SELECT REPLACE(‘www.farukerdm.com’, ‘farukerdm’, ‘farukerdem’); |
REVERSE(): Reverse the characters in a string
|
1 |
select reverse(‘abcd’) |
RIGHT(): Returns the specified rightmost number of characters
|
1 |
SELECT RIGHT(‘farukerdem’, 5); |
RTRIM(): Removes trailing spaces
|
1 |
SELECT RTRIM(‘faruk ‘); |
SUBSTRING(), SUBSTR(): Returns the substring as specified
|
1 |
select SUBSTRING(‘FARUKERDEM’,6,10) AS "6th Character and After" |
TRIM(): Removes leading and trailing spaces
|
1 |
select trim(‘ faruk ‘) |
UPPER(): Converts to uppercase
|
1 |
SELECT UPPER(‘faruk’); |
