concat(...any) — Concatenate values, skipping NULLs

Last updated: 2026-11-04

concat(...any) — Concatenate values, skipping NULLs

concat() converts any number of values to text and joins them, silently skipping NULL arguments instead of letting them poison the whole result. Compared with the || operator it is the safer choice when some fields may be missing; if you specifically want NULL to propagate, use ||.

Kindfunction
Example LanguageSQL

📝 Syntax

concat(value1 any, value2 any, ...) → text
concat_ws(separator text, value1 any, value2 any, ...) → text

⚙️ Parameters

value anyValues to join; any type is accepted and cast to text. NULL arguments are skipped.
separator textconcat_ws only: the separator, inserted between non-NULL values. Type text.

Returns:text — the joined string. Returns an empty string when every argument is NULL.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

 id | pipe_result  | concat_result | concat_ws_result
----+--------------+---------------+------------------
  1 | Ada Lovelace | Ada Lovelace  | Ada Lovelace
  2 |              | Grace         | Grace
  3 |              |  Hopper       | Hopper
(3 rows)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QShould I use concat() or ||?
AUse concat() when optional fields should be skipped automatically; use || when you want NULL to propagate explicitly, for example to flag missing data.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏