PostgreSQL – CONCAT Function
The CONCAT()
function is used to concatenate two or more strings together. It takes multiple string arguments and returns a single string by concatenating those arguments in the order they are provided. If any of the arguments are NULL
, the resulting concatenated string will also be NULL
.
The syntax of the CONCAT()
function is as follows:
CONCAT(string1, string2, ...)
where string1
, string2
, etc are the strings you want to concatenate.
Here’s a simple example of how to use the CONCAT()
function in PostgreSQL:
SELECT CONCAT('Hello', ' ', 'World') AS concatenated_text;
In this example, the CONCAT()
function concatenates the strings “Hello”, a space, and “World” to create the result “Hello World”.
You can also achieve the same concatenation using the ||
operator in PostgreSQL:
SELECT 'Hello' || ' ' || 'World' AS concatenated_text;
Both the CONCAT()
function and the ||
operator are commonly used to combine strings in SQL queries.