PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
Home / PostgreSQL String Functions

PostgreSQL String Functions

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

FunctionDescriptionExampleResult
ASCIIReturn the ASCII code value of character or Unicode code point of a UTF8 characterASCII(‘A’)65
CHRConvert an ASCII code to a character or a Unicode code point to a UTF8 characterCHR(65)‘A’
CONCATConcatenate two or more strings into oneCONCAT(‘A’,’B’,’C’)‘ABC’
CONCAT_WSConcatenate strings with a separatorCONCAT(‘,’,’A’,’B’,’C’)‘A,B,C’
FORMATFormat arguments based on a format stringFORMAT(‘Hello %s’,’PostgreSQL’)‘Hello PostgreSQL’
INITCAPConvert words in a string to title caseINITCAP(‘hI tHERE’)Hi There
LEFTReturn the first n character in a stringLEFT(‘ABC’,1)‘A’
LENGTHReturn the number of characters in a stringLENGTH(‘ABC’)3
LOWERConvert a string to lowercaseLOWER(‘hI tHERE’)‘hi there’
LPADPad on the left a a string with a character to a certain lengthLPAD(‘123′, 5, ’00’)‘00123’
LTRIMRemove the longest string that contains specified characters from the left of the input stringLTRIM(‘00123’)‘123’
MD5Return MD5 hash of a string in hexadecimalMD5(‘ABC’)
POSITIONReturn the location of a substring in a stringPOSTION(‘B’ in ‘A B C’)3
REGEXP_MATCHESMatch a POSIX regular expression against a string and returns the matching substringsSELECT REGEXP_MATCHES(‘ABC’, ‘^(A)(..)$’, ‘g’);{A,BC}
REGEXP_REPLACEReplace substrings that match a POSIX regular expressionby a new substringREGEXP_REPLACE(‘John Doe’,'(.*) (.*)’,’\2, \1′);‘Doe, John’
REPEATRepeat string the specified number of timesREPEAT(‘*’, 5)‘*****’
REPLACEReplace all occurrences in string of substring from with substring toREPLACE(‘ABC’,’B’,’A’)‘AAC’
REVERSEReturn reversed string.REVERSE(‘ABC’)‘CBA’
RIGHTReturn last n characters in the string. When n is negative, return all but first |n| characters.RIGHT(‘ABC’, 2)‘BC’
RPADPad on the right of a string with a character to a certain lengthRPAD(‘ABC’, 6, ‘xo’)‘ABCxox’
RTRIMRemove the longest string that contains specified characters from the right of the input stringRTRIM(‘abcxxzx’, ‘xyz’)‘abc’
SPLIT_PARTSplit a string on a specified delimiter and return nth substringSPLIT_PART(‘2017-12-31′,’-‘,2)’12’
SUBSTRINGExtract a substring from a stringSUBSTRING(‘ABC’,1,1)A’
TRIMRemove the longest string that contains specified characters from the left, right, or both of the input stringSUBSTRING(‘ABC’,1,1)‘A’
UPPERConvert a string to uppercaseUPPER(‘hI tHERE’)‘HI THERE’
Previous Tutorial: PostgreSQL Date Functions
Next Tutorial: PostgreSQL Math Functions

PostgreSQL String Functions

  • ASCII
  • CONCAT
  • CHR
  • FORMAT
  • LEFT
  • LENGTH
  • LPAD
  • MD5
  • POSITION
  • REGEXP_MATCHES
  • REGEXP_REPLACE
  • RIGHT
  • REPLACE
  • SPLIT_PART
  • SUBSTRING
  • TRANSLATE
  • TRIM
  • TO_CHAR
  • TO_NUMBER

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL ANY Operator
  • PostgreSQL EXISTS
  • How To Delete Duplicate Rows in PostgreSQL
  • PostgreSQL TO_CHAR Function
  • PostgreSQL TO_NUMBER Function
  • PostgreSQL TO_TIMESTAMP Function
  • PostgreSQL CEIL Function
  • PostgreSQL MOD Function
  • PostgreSQL FLOOR Function
  • PostgreSQL ABS Function

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2017 by PostgreSQL Tutorial Website. All Rights Reserved.