Postgres 18 just shipped, and it’s already available on Neon. Deploy it in seconds and try the new features
/String Functions

PostgreSQL String Functions

This page provides the most commonly used PostgreSQL string functions that allow you to manipulate string data effectively.

FunctionDescriptionExampleResult
ASCII Return the ASCII code value of a character or Unicode code point of a UTF8 characterASCII(‘A’)65
CHR Convert an ASCII code to a character or a Unicode code point to a UTF8 characterCHR(65)‘A’
CONCAT Concatenate two or more strings into oneCONCAT(‘A’,’B’,’C’)‘ABC’
CONCAT_WS Concatenate strings with a specified separator.CONCAT_WS(‘,’,’A’,’B’,’C’)‘A,B,C’
FORMAT Format a string based on a templateFORMAT(‘Hello %s’,’PostgreSQL’)‘Hello PostgreSQL’
INITCAP Convert words in a string to title caseINITCAP(‘hI tHERE’)Hi There
LEFT Return the first n character in a stringLEFT(‘ABC’,1)‘A’
LENGTH Return the number of characters in a stringLENGTH(‘ABC’)3
LOWER Convert a string to lowercaseLOWER(‘hI tHERE’)‘hi there’
LPAD Extending a string to a length by padding specified characters on the leftLPAD(‘123′, 5, ’00’)‘00123’
LTRIM Remove the longest string that contains specified characters from the left of the input stringLTRIM(‘00123’)‘123’
MD5 Return MD5 hash of a string in hexadecimalMD5(‘ABC’)
POSITION Return the location of a substring in a stringPOSITION(‘B’ in ‘A B C’)3
REGEXP_MATCHES Replace substrings that match a POSIX regular expression with a new substringSELECT REGEXP_MATCHES(‘ABC’, ‘^(A)(..)$’, ‘g’);{A,BC}
REGEXP_REPLACE Replace a substring using regular expressions.REGEXP_REPLACE(‘John Doe’,'(.*) (.*)’,’2,円 1円′);‘Doe, John’
REPEAT Repeat a string the specified number of times.REPEAT(‘*’, 5)‘*****’
REPLACE Replace a substring within a string with a new one.REPLACE(‘ABC’,’B’,’A’)‘AAC’
REVERSE Replace a substring within a string with a new oneREVERSE(‘ABC’)‘CBA’
RIGHT Return the last n characters in the string. When n is negative, return all but the first \n characters.RIGHT(‘ABC’, 2)‘BC’
RPAD Extend a string to a length by appending specified characters.RPAD(‘ABC’, 6, ‘xo’)‘ABCxox’
RTRIM Remove the longest string that contains specified characters from the right of the input stringRTRIM(‘abcxxzx’, ‘xyz’)‘abc’
SPLIT_PART Split a string on a specified delimiter and return nth substringSPLIT_PART(‘2017年12月31日′,’-‘,2)’12’
SUBSTRING Extract a substring from a stringSUBSTRING(‘ABC’,1,1)A’
TRIM Remove the leading and trailing characters from a string.TRIM(‘ ABC ‘)‘ABC’
UPPER Convert a string to uppercaseUPPER(‘hI tHERE’)‘HI THERE’

Last updated on

Was this page helpful?
Thank you for your feedback!

AltStyle によって変換されたページ (->オリジナル) /