PostgreSQL – CONCAT_WS Function
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 ('***', 'Beginner ', 'for', 'Beginner');
Output:
Contact Us