Strings

CONCAT

Joins several values into one string, skipping NULL.

Syntax

CONCAT(<value1>, <value2>, …)
CONCAT_WS(<separator>, <value1>, <value2>, …)

Converts the arguments to text and joins them one after another. Unlike the || operator, NULL doesn't “swallow” the whole result — it's simply skipped. CONCAT_WS puts a separator between the values for you.

Data for the examples

employees

namedepartmentsalarybonusphone
Emmabackend1200300+44 7700 900123
Liambackend1000NULLNULL
Oliviafrontend1350150+44 7700 900456
Noahfrontend950NULL+44 7700 900789
Sophiadesign1200200NULL

These tables already exist in the sandbox — the examples below use them. Want to try this in your own database? Copy the SQL.

Join several parts
SELECT CONCAT('Emma', ' ', 'Wilson') AS full_name;
full_name
Emma Wilson
A label for each employee
SELECT CONCAT(name, ' (', department, ')') AS label
FROM employees;
label
Emma (backend)
Liam (backend)
Olivia (frontend)
Noah (frontend)
Sophia (design)
CONCAT versus || where there's NULL
SELECT name,
name || ', ' || phone AS with_pipes,
CONCAT(name, ', ', phone) AS with_concat
FROM employees;
namewith_pipeswith_concat
EmmaEmma, +44 7700 900123Emma, +44 7700 900123
LiamNULLLiam,
OliviaOlivia, +44 7700 900456Olivia, +44 7700 900456
NoahNoah, +44 7700 900789Noah, +44 7700 900789
SophiaNULLSophia,

Liam and Sophia have no phone number: || gives NULL for the whole string, while CONCAT just skips the empty part.

Watch out

CONCAT keeps a separator even where there's no value: CONCAT('Liam', ', ', NULL) gives Liam, with a trailing comma. To put separators only between existing values, use CONCAT_WS(', ', 'Liam', NULL) — you'll get just Liam.

Numbers and dates are converted to text automatically, but PostgreSQL picks how they look. If you need your own format, such as 13.09.2026, use TO_CHAR first.

Related functions

Learn more in the course