Open In App

PostgreSQL – CONCAT_WS Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In PostgreSQL, the CONCAT_WS function is used to concatenate strings with a separator. Like the CONCAT function, the CONCAT_WS function is also variadic and ignored NULL values.

The following illustrates the syntax of the CONCAT_WS function.

Syntax: CONCAT_WS(separator, string_1, string_2, ...);

Let’s analyze the above syntax:

  • The separator is a string that is used to separate the resultant strings.
  • The string_1, string_2, are strings that is to be converted.
  • The CONCAT_WS function returns a combined string that is the combination of string_1, string_2, etc., separated by the separator.

Example 1:

The following statement concatenates the symbols (ie, ^,+,-,/):

SELECT CONCAT_WS ('^^^', '+++ ', '---', '///');

Output:

Example 2:

The below statement uses the CONCAT_WS function to concatenate three strings into one:

SELECT
 CONCAT_WS ('***', 'geeks ', 'for', 'geeks');

Output:


Last Updated : 08 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads