PostgreSQL: String Functions and Operators

I kind of skipped over the functions/operators section of the PostgreSQL documentation when reading it. I want to review the sections that I think would be useful to me.

Date Created:
1 22

References



Notes


This section describes functions and operators for examining and manipulating string values. Strings in this context include values of the types char, varchar, and text. Most of the functions below work on all of these types.

Function

Return Type

Description

string || string

text

String concatenation

string || non-string

text

String concatenation with one non-string input

char_length(string)

int

Number of characters in string

lower(string)

text

Convert string to lower case

overlay(string placing string from int [for int])

text

Replace substring

position(substring in string)

int

Location of specified substring

substring(string [from int] [for int])

text

Extract substring

substring(string from pattern)

text

Extract substring from POSIX regular expression

upper(string)

text

Convert string to upper case

trim([leading | trailing | both] [characters] from string)

text

Remove the longest string containing only the characters (space by default) from the start/end/both ends of the string

initcap(string)

text

Convert the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters

regexp_matches(string text, pattern text, replacement text, [, flags text])

setof text[]

Return all captured substrings resulting from matching a POSIX regular expression against the string

regexp_replace(string text, pattern text, replacement text [, flags text])

text

Replace substring(s) matching a POSIX regular expression

regexp_split_to_array(string text, pattern text [, flags text])

text[]

Split string using a POSIX regular expression as the delimeter

regexp_split_to_table(string text, pattern text [, flags text])

setof text

Split string using a POSIX regular expression as the delimiter

replace(string text, from text, to text)

text

Replace all occurrences in string of substring from with substring to


Comments

You have to be logged in to add a comment

User Comments

Insert Math Markup

ESC
About Inserting Math Content
Display Style:

Embed News Content

ESC
About Embedding News Content

Embed Youtube Video

ESC
Embedding Youtube Videos

Embed TikTok Video

ESC
Embedding TikTok Videos

Embed X Post

ESC
Embedding X Posts

Embed Instagram Post

ESC
Embedding Instagram Posts

Insert Details Element

ESC

Example Output:

Summary Title
You will be able to insert content here after confirming the title of the <details> element.

Insert Table

ESC
Customization
Align:
Preview:

Insert Horizontal Rule

#000000

Preview:


View Content At Different Sizes

ESC

Edit Style of Block Nodes

ESC

Edit the background color, default text color, margin, padding, and border of block nodes. Editable block nodes include paragraphs, headers, and lists.

#ffffff
#000000

Edit Selected Cells

Change the background color, vertical align, and borders of the cells in the current selection.

#ffffff
Vertical Align:
Border
#000000
Border Style:

Edit Table

ESC
Customization:
Align:

Upload Lexical State

ESC

Upload a .lexical file. If the file type matches the type of the current editor, then a preview will be shown below the file input.

Upload 3D Object

ESC

Upload Jupyter Notebook

ESC

Upload a Jupyter notebook and embed the resulting HTML in the text editor.

Insert Custom HTML

ESC

Edit Image Background Color

ESC
#ffffff

Insert Columns Layout

ESC
Column Type:

Select Code Language

ESC
Select Coding Language

Insert Chart

ESC

Use the search box below

Upload Previous Version of Article State

ESC