PostgreSQL CONCATENATE Operator

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL CONCATENATE(||) Operator

CONCATENATE(||) Operator

The PostgreSQL concatenate operator ( || ) is used to concatenate two or more strings and non strings.

Syntax :

string1 || string2 or sting || non-string or non-string || string

PostgreSQL Version : 9.3

Example :

SELECT 'w'||3||'resource' AS "Concatenate Operator ( || )"; 

Output :

 Concatenate Operator ( || )
-----------------------------
 w3resource
(1 row)

PostgreSQL CONCATENATE OPERATOR ( | | ) using Column Name

If we want to display the first name, last name and concatenate of the first name and last name of that employee who belongs to the dept 15 from the employees table, the following SQL can be executed :

SELECT first_name,last_name,
first_name||' '||last_name AS "Name of Employee"
FROM employees WHERE department_id=20;

Output :

 first_name | last_name | Name of Employee
------------+-----------+-------------------
 Michael    | Hartstein | Michael Hartstein
 Pat        | Fay       | Pat Fay
(2 rows)