w3resource

PostgreSQL CONCAT() function

CONCAT() function

The PostgreSQL concat() function is used to concatenate two or more strings except NULL specified in the arguments.

Syntax:

concat(<string1>,[<string2>,<string3>,...])

PostgreSQL Version : 9.3

Pictorial Presentation of PostgreSQL CONCAT() function<

Pictorial presentation of PostgreSQL CONCAT() function

Example: PostgreSQL CONCAT() function:

In the example below the strings specified in the argument have been concatenated and returns a string.

SELECT concat('w',3,'r', 'esource','.','com');

Sample Output:

    concat
----------------
 w3resource.com
(1 row)

Example of PostgreSQL CONCAT() function with NULL :

In the example below, the concat function ignore the NULL and displays the result.

SELECT concat('w',3,'r', 'esource',NULL,'.','com');

Sample Output:

    concat
----------------
 w3resource.com
(1 row)

Example of PostgreSQL CONCAT() function using column :

Sample Table: employees


If we want to display the first_name, last_name, and Name of the employee for those employees who belongs to the department which ID is 100 from employees table the following statement can be executed.

SELECT employee_id,first_name,last_name,
concat(first_name,' ',last_name) "Name of the Employee" 
FROM employees
WHERE department_id=100;

Sample Output:

 employee_id | first_name  | last_name | Name of the Employee
-------------+-------------+-----------+----------------------
         108 | Nancy       | Greenberg | Nancy Greenberg
         109 | Daniel      | Faviet    | Daniel Faviet
         110 | John        | Chen      | John Chen
         111 | Ismael      | Sciarra   | Ismael Sciarra
         112 | Jose Manuel | Urman     | Jose Manuel Urman
         113 | Luis        | Popp      | Luis Popp
(6 rows)

Previous: CHR function
Next: INITCAP function



Follow us on Facebook and Twitter for latest update.