PostgreSQL- CONCAT Function
In PostgreSQL, the CONCAT function is used to concatenate two or more strings into one.
Syntax: CONCAT(string_1, string_2, ...)
Let’s analyze the above syntax:
- The CONCAT function accepts a list of string convertible arguments. A string in this context means any of the following data types: char, varchar, or text.
- The CONCAT function is variadic meaning that the CONCAT function can accept an array as the argument. Here it is required to mark the array with the VARIADIC keyword. The CONCAT function considers every array element as an argument.
- Contrary to the concatenation operator ( || ), the CONCAT function ignores NULL arguments.
Example 1:
The below statement uses the CONCAT function to concatenate three strings into one:
SELECT CONCAT ('Beginner', 'for', 'Beginner');
Output:
Example 2:
The following statement concatenates values in the first_name and last_name columns of the actor table in the sample database, ie, dvdrental.
SELECT CONCAT (first_name, ' ', last_name) AS "Full name" FROM actor;
Output:
Contact Us