totn PostgreSQL Functions

PostgreSQL: || Operator

This PostgreSQL tutorial explains how to use the PostgreSQL || concatenate operator with syntax and examples.

Description

The PostgreSQL || operator allows you to concatenate 2 or more strings together.

Syntax

The syntax for the || operator in PostgreSQL is:

string1 || string2 || string_n

Parameters or Arguments

string1
The first string to concatenate.
string2
The second string to concatenate.
string_n
The nth string to concatenate.

Applies To

The || operator can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some concatenation examples and explore how to use the || operator in PostgreSQL.

For example:

postgres=# SELECT 'Tech on' || ' the Net' AS result;
     result
------------------
 Tech on the Net
(1 row)

postgres=# SELECT 'TechOnTheNet' || '.com' AS result;
     result
------------------
 TechOnTheNet.com
(1 row)

postgres=# SELECT 'a' || 'b' || 'c' || 'd' AS result;
 result
--------
 abcd
(1 row)