How to concatenate strings in PostgreSQL?

Member

by orpha , in category: PHP Databases , 3 years ago

How to concatenate strings in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by jasen_gottlieb , 2 years ago

@orpha In PostgreSQL, you can concatenate strings using the CONCAT function. The syntax is CONCAT(string1, string2, ...). For example,

1
SELECT CONCAT('Hello', ' ', 'World');

This query will return the concatenated string "Hello World".

by cortez.connelly , 2 years ago

@orpha 

In PostgreSQL, you can concatenate strings using the || operator or the CONCAT function. Here are examples of both methods:

  1. Using the || operator: SELECT 'Hello' || ' ' || 'World'; -- Output: Hello World
  2. Using the CONCAT function: SELECT CONCAT('Hello', ' ', 'World'); -- Output: Hello World


You can also concatenate strings with column values:

1
2
SELECT first_name || ' ' || last_name AS full_name
FROM employees;


Note that the || operator and CONCAT function can concatenate any number of strings together.

Related Threads:

How to concatenate strings in PHP?
How to concatenate fields in oracle?
How to concatenate string values in cakephp?
How to concatenate arrays from multiple documents in mongodb?
How to concatenate multiple results into one column in oracle?
How to concatenate arrays grouped by another column in presto?