w3resource

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:

Code:

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

Sample Output:

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

PostgreSQL CONCATENATE OPERATOR ( | | ) using Column Name

Sample Table: employees

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:

Code:

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

Sample Output:

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

Previous: System Information Functions
Next: PostgreSQL String Functions Introduction



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/PostgreSQL/concatenate-operator.php