Concatenation operator ||

Last updated: 2026-11-04

Concatenation operator ||

|| joins two values into a single text result and is the only string concatenation operator in PostgreSQL (+ does not work for text). It also has an array flavour: array || array concatenates them end to end, and array || scalar appends the scalar to the end of the array. Text concatenation propagates NULL — if either side is NULL the result is NULL — so use concat() or concat_ws() when NULLs should be skipped.

Kindoperator
Example LanguageSQL

📝 Syntax

a || b            -- text concatenation
array || array      -- array concatenation
array || element    -- array append

Precedence: || falls in the "any other operator" tier, below `* / %` and binary `+ -` but above the comparison operators. So `1 + 2 || 'x'` is '3x' (add first) and `'a' || 'b' = 'ab'` is true (concatenate first). || is left-associative.

⚙️ Parameters

aLeft operand: text, an array, or a scalar compatible with b; a NULL makes the text concatenation NULL.
bRight operand: text, an array, or a scalar appendable to an array.

Returns:Text concatenation returns text; array concatenation returns an array of the input element type.

▶ 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:

SELECT id, first_name || ' ' || last_name AS full_name FROM t_concat ORDER BY id
id | full_name   
---+-------------
 1 | Ada Lovelace
 2 | NULL        
(2 rows)

SELECT 'Postgre' || 'SQL' AS text_concat, ARRAY[1, 2] || ARRAY[3, 4] AS array_concat, ARRAY[1, 2] || 3 AS array_append
text_concat | array_concat | array_append
------------+--------------+-------------
PostgreSQL  | {1,2,3,4}    | {1,2,3}     
(1 row)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow do || and concat() differ?
A|| returns NULL if any operand is NULL, while concat() ignores NULL arguments. concat_ws(sep, ...) is better for joining optional columns because it also skips NULLs.
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%

🙏 帮我们做得更好

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

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