SQL CONCAT
Joins two or more text values together into one — and unlike the || operator, safely treats NULL as an empty string instead of contaminating the whole result.
What & Why
CONCAT(a, b, c, ...) joins any number of values into a single string, converting non-text values (like numbers) automatically. Its standout behavior: if any input is NULL, CONCAT simply treats it as an empty string and keeps going — it doesn't propagate NULL the way most functions do.
See How It Works
Product wants to compare CONCAT with || while building feature labels from the nullable deprecated_at column.
| id | name | description | team | released_at | deprecated_at |
|---|---|---|---|---|---|
| 1 | Activation Checklist | Guides new users through setup | growth | 2024-01-20 | NULL |
| 2 | CSV Export | Exports report data | platform | 2024-02-14 | NULL |
| 3 | Invite Nudges | Prompts workspace collaboration | growth | 2024-03-05 | NULL |
| 4 | Legacy Dashboard | Original reporting surface | analytics | 2023-08-10 | 2024-06-01 |
| id | name | deprecated_at | concat_label | operator_label |
|---|---|---|---|---|
| 1 | Activation Checklist | NULL | Activation Checklist · | NULL |
| 2 | CSV Export | NULL | ? | ? |
| 3 | Invite Nudges | NULL | ? | ? |
| 4 | Legacy Dashboard | 2024-06-01 | ? | ? |
CONCAT treats the missing date as empty text, while || propagates NULL.
SELECT
id,
name,
deprecated_at,
CONCAT(name, ' · ', deprecated_at::text) AS concat_label,
name || ' · ' || deprecated_at::text AS operator_label
FROM product.features
ORDER BY id;Practice this concept
Product compares CONCAT with || while building feature labels from nullable deprecated_at.
productPrefix tables with product.table_name.
idnamedeprecated_atconcat_labeloperator_labelproduct.features| Column | Type |
|---|---|
| id | integer |
| name | text |
| description | text |
| team | text |
| released_at | timestamp with time zone |
| deprecated_at | timestamp with time zone |
| internal_priority | integer |
Sign up free to try it on a real business scenario