Jump to: navigation, search

PostgreSQL CONCAT WS

From w3cyberlearnings

Contents

Postgresql concat_ws

This function concatenates all arguments with a separator. The first argument is the separator.

Syntax concat_ws

  • Separator: a separator of a given word
  • word1: word input
  • word2: second word input
CONCAT_WS(Separator,word1,word2,...);

Example 1

test2=# SELECT concat_ws('&','a=apple','b=banana','c=coconut');
         concat_ws          
----------------------------
 a=apple&b=banana&c=coconut
(1 row)

Example 2

Generate a URL

test2=# SELECT concat_ws('&',concat('f=',user_firstname),concat('l=',user_lastname)) url
test2-# FROM profile;
       url       
-----------------
 f=Jim&l=Jkim
 f=king&l=queen
 f=Jammi&l=weeks
 f=Bob&l=Mark
 f=&l=
(5 rows)

Related Links


Navigation
Web
SQL
MISC
References