PostgreSQL 18 reference · String Functions

PostgreSQL || Concatenation Operator

Join strings with the || operator. If either side is NULL the result is NULL; use concat() to skip NULLs instead.

PostgreSQL 18

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string || string

Parameters

ParameterDescription
string Values to join; non-text values are converted when one side is text.

Return value

Text, or NULL.

Examples

Build a label
SELECT name || ' (' || country || ')' AS label
FROM customers
LIMIT 2;

Output

       label
-------------------
 Ada Lovelace (UK)
 Alan Turing (UK)
(2 rows)

Run this on your computer — see “Get Started” for setup.

NULL turns the result NULL
SELECT name || ', ' || city AS with_pipes, concat(name, ', ', city) AS with_concat
FROM customers
WHERE customer_id = 7;

Output

 with_pipes |   with_concat
------------+------------------
 NULL       | Barbara Liskov,
(1 row)

Run this on your computer — see “Get Started” for setup.

In other languages

Was this page helpful?