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<

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;