The BigQuery CONCAT function allows you to combine (concatenate) one more values into a single result.
Alternatively, you can use the concatenation operator || to achieve the same output.
CONCAT(value1[, ...])
or
value1 [|| ...]
SELECT CONCAT(first_name, ' ', last_name) AS full_names_by_function FROM ( SELECT 'Michael' AS first_name, 'Scott' AS last_name UNION ALL ( SELECT 'Pam' AS first_name, 'Beesly' AS last_name) UNION ALL ( SELECT 'Kevin' AS first_name, 'Malone' AS last_name) ) AS names_table
Alternatively the same result could be achieved by:
firstname || ' ' || last_name
The CONCAT function will do this automatically, for example:
SELECT
CONCAT(Data.TEXT, Data.DATE) AS with_date
FROM
(
SELECT
'The date is: ' AS TEXT,
CAST('2020-10-01' AS DATE) AS DATE
) AS Data
If you want to change the format of the date before combining it with other columns you can use the FORMAT_DATE function on the date column first. For example:
SELECT
CONCAT(Data.TEXT, FORMAT_DATE('%B', Data.DATE)) AS with_formatted_date
FROM
(
SELECT
'The month is ' AS TEXT,
CAST('2020-10-01' AS DATE) AS DATE
) AS Data
This error occurs when one of the input columns to the CONCAT function can't be cast to a STRING or BYTES , for example an array column or struct column.