Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create table using a variable name in the BigQuery UI

I am trying to write a BigQuery script that I can store as a procedure, I would like one of the arguments I pass to be used in the table name that is written out by the script, for example:

DECLARE id STRING;
SET id = '123';

CREATE OR REPLACE TABLE test.id AS(
SELECT * FROM dataset.table
)

However, in this example the table is created with the name id rather than the value of the "id" variable, 123. Is there any way I can dynamically create a table using the value of a declared variable in the BigQuery UI?

like image 675
Ben P Avatar asked Dec 11 '22 01:12

Ben P


1 Answers

Why not just use Execute Immediate with concat if you know the table schema?

EXECUTE IMMEDIATE CONCAT('CREATE TABLE `', id, '` (column_name STRING)');
like image 79
Mikey Avatar answered Feb 11 '23 13:02

Mikey