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
Syntax
string || string
Parameters
| Parameter | Description |
|---|---|
string |
Values to join; non-text values are converted when one side is text. |
Return value
Text, or NULL.
Examples
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.
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
||· SQLite
Related
CONCAT()· Join any number of values into one string, treating NULL arguments as empty strings.CONCAT_WS()· Join values with a separator between them, skipping NULLs. The first argument is the separator.COALESCE()· Return the first argument that isn't NULL. The standard way to replace NULL with a default.- SQL String Functions · tutorial