Skip to content

CONCAT_WS

Concatenate a series of strings, using the first argument as a separator between the strings. This function also accepts values that are not character strings, such as integers and timestamps.

NULL arguments are ignored.

CONCAT_WS(separator, string [, string [ , … ] ])

For example, combine two character columns and separate them with a hyphen (-):

premdb=# SELECT CONCAT_WS('-',nickname,city) FROM team LIMIT 5;
     concat_ws      
---------------------
 Gunners-London
 Villains-Birmingham
 Tykes-Barnsley
 Blues-Birmingham
 Rovers-Blackburn
(5 rows)

Combine two integer columns and separate them with a colon:

premdb=# select concat_ws(':',htid,atid) from team order by htid;
 concat_ws 
-----------
 2:51
 3:52
 4:53
 5:54
 6:55
 7:56
...