Friday, January 24, 2020

CONCAT and CONCAT_WS #2 and #3 of #100PostgreSQLFunctions

This post is a part of the project #100PostgreSQLFunctions, which aims to explain the meaning of 100 PostgreSQL functions and how to use them. For the full list of functions click here.

CONCAT is a function to concatenate two or more strings into one.
This function can have two or more arguments, each of the strings to merge.

Examples:

SELECT
    CONCAT('Hello', 'world!');

    concat 
--------------
 Helloworld!
(1 row)


SELECT
    CONCAT('Hello', ' ', 'world!');

    concat 
--------------
 Hello world!
(1 row)


CONCAT_WS is a function to concatenate two or more strings with a separator. This function can have three or more arguments:
  • separator is the string to between the others, it could be a space or whatever; 
  • string1 is the first string to merge
  • string2 is the other string to merge
  • string_n is the third or more string to merge;

Example:

SELECT
    CONCAT_WS(' ', 'Hello', 'world!');

    concat 
--------------
 Hello world!
(1 row)

No comments:

Post a Comment