concat()

A function for concatenating values

concat() is a system function for concatenating arbitrary values into a text string.

concat() was added in PostgreSQL 9.1.

Usage

concat ( val1 any [, val2 any [, ...] ] ) → text

To concatenate values using a delimiter, use concat_ws().

To aggregate string values from columns in a query, use string_agg().

Change history

Examples

Basic usage example for concat():

postgres=# SELECT concat('foo', 'bar');
 concat 
--------
 foobar
(1 row)

Differing data types can be concatenated:

postgres=# SELECT concat('foo', 1, 1.5, ARRAY[2,3], '{"4":"baz"}'::json);
         concat          
-------------------------
 foo11.5{2,3}{"4":"baz"}
(1 row)

NULL values are ignored:

postgres=# SELECT concat('foo', NULL, 'bar');
 concat 
--------
 foobar
(1 row)

An empty string will be returned if all provided values are NULL:

postgres=# SELECT concat(NULL, NULL) IS NULL;
 ?column? 
----------
 f
(1 row)

Categories

String manipulation, System function

See also

concat_ws(), string_agg()