Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery : combine two columns

I am just wondering how can we combine 2 fields in Bigquery.

This is my SQL

SELECT
 cast(tbl.table_name as string) + '.' + cast(col.column_name as string)
FROM 
xy.INFORMATION_SCHEMA.TABLES tbl
INNER JOIN 
xy.INFORMATION_SCHEMA.COLUMNS col
ON tbl.table_name = col.table_name

This is the error I'm getting

No matching signature for operator + for argument types: STRING, STRING. Supported signatures: INT64 + INT64; FLOAT64 + FLOAT64; NUMERIC + NUMERIC at [3:2]

like image 772
Aced Avatar asked Sep 08 '26 01:09

Aced


2 Answers

For BigQuery Standard SQL

You can just use CONCAT() function without CAST'ing string to string as in below example

CONCAT(tbl.table_name, '.', col.column_name)     

Yet another option is FORMAT() function

FORMAT('%s.%s', tbl.table_name, col.column_name)   
like image 175
Mikhail Berlyant Avatar answered Sep 11 '26 11:09

Mikhail Berlyant


You can use concat as defined in this link

This is the SQL

SELECT
 CONCAT(cast(tbl.table_name as string), '.',cast(col.column_name as string))
FROM 
`dataset.INFORMATION_SCHEMA.TABLES` tbl
INNER JOIN 
`dataset.INFORMATION_SCHEMA.COLUMNS` col
ON tbl.table_name = col.table_name

Output

+---------------------+
| fo_                 |
+---------------------+
| Table1.col          |
| Table1.col2         |
+---------------------+
like image 38
Tamir Klein Avatar answered Sep 11 '26 13:09

Tamir Klein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!