Cloud

concat

Use the concat() function to concatenate one or more input values into a single result. It supports all data types in Redpanda SQL, except TIMESTAMPTZ. The output is returned as a concatenation of the input values.

Special cases: Skips NULL values and returns the concatenation of non-NULL inputs. Returns NULL only when there are no input rows.

Examples

Basic concat() function

This example uses the concat() function to concatenate three values into a single result:

SELECT CONCAT ('Oxla', '.', 'com') AS "Website";

The query returns:

+------------+
| Website    |
+------------+
| Oxla.com   |
+------------+

concat() function using column

This example uses a payment table that stores customer payment data:

CREATE TABLE payment (
  paymentid int,
  custFirstName text,
  custLastName text,
  product text,
  ordertotal float
);
INSERT INTO payment
    (paymentid, custFirstName, custLastName, product, ordertotal)
VALUES
    (9557451,'Alex','Drue','Latte',2.10),
    (9557421,'Lana','Rey','Latte',2.10),
    (9557411,'Tom','Hanks','Americano',1.85),
    (9557351,'Maya','Taylor','Cappuccino',2.45),
    (9557321,'Smith','Jay','Cappuccino',2.45),
    (9557311,'Will','Ritchie','Americano',1.85);
SELECT * FROM payment;

This query displays the table:

+------------+----------------+----------------+--------------+---------------+
| paymentid  | custFirstName  | custLastName   | product      | ordertotal    |
+------------+----------------+----------------+--------------+---------------+
| 9557451    | Alex           | Drue           | Latte        | 2.10          |
| 9557421    | Lana           | Rey            | Latte        | 2.10          |
| 9557411    | Tom            | Hanks          | Americano    | 1.85          |
| 9557351    | Maya           | Taylor         | Cappuccino   | 2.45          |
| 9557321    | Smith          | Jay            | Cappuccino   | 2.45          |
| 9557311    | Will           | Ritchie        | Americano    | 1.85          |
+------------+----------------+----------------+--------------+---------------+

This query concatenates values in the custFirstName and custLastName columns of the payment table:

SELECT CONCAT  (custFirstName, ' ', custLastName) AS "Customer Name"
FROM payment;

This displays an output where spaces separate the first and last names.

+-----------------+
| Customer Name   |
+-----------------+
| Tom Hanks       |
| Lana Rey        |
| Alex Drue       |
| Will Ritchie    |
| Smith Jay       |
| Maya Taylor     |
+-----------------+

concat() function with NULL

This example shows how to use the concat() function to concatenate a string with a NULL value:

SELECT CONCAT('Talent Source ',NULL) AS "concat";

The result shows that the concat function will skip the NULL value:

+------------------+
| concat           |
+------------------+
| Talent Source    |
+------------------+