How to concatenate strings in PostgreSQL?

Member

by orpha , in category: PHP Databases , 2 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 , a year 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.