问题
I can code like this in Oracle to create tables dynamically using "execute immediate 'sql query..'" command.
create or replace function make_a_table1(p_table_name varchar2, p_column_name varchar2, p_data_type varchar2) return varchar2 is
var varchar2(150);
sydt varchar2(30);
pragma autonomous_transaction;
begin
select to_char(sysdate,'HH24_MI_SS') into sydt from dual;
dbms_output.put_line(sydt);
var :='create table '||p_table_name||'_'||sydt||' ( '||p_column_name||' '||p_data_type||')';
dbms_output.put_line(var);
execute immediate var;
commit;
return 'Table Created Successfully';
end;
Is it possible to Achieve this in BigQuery functions?
回答1:
You will have to use an external call through an API. I use Python for this. Both parameter base queries and Dynamic queries. Big query at the moment as far as i know does not support variables or an execute sql command, using SQL directly ( like TSQL )
回答2:
To run a dynamic query in SQL, you need to:
- Construct the query using string operations and functions.
- Execute the constructed string as a query.
BigQuery supports #1, but it does not have an EXEC statement for #2 as of this writing.
If you want to run dynamic queries in BigQuery, you will have to construct the string in a cloud function (or similar environment) and then send the query to BigQuery via the API.
回答3:
There are two "modes" you can run BigQuery query in - interactive and batch .
By default, BigQuery runs interactive queries, which means that the query is executed as soon as possible. Interactive queries count towards your concurrent rate limit and your daily limit.
BigQuery also offers batch queries. BigQuery queues each batch query on your behalf, and starts the query as soon as idle resources are available, usually within a few minutes. If BigQuery hasn't started the query within 24 hours, BigQuery changes the job priority to interactive. Batch queries don't count towards your concurrent rate limit, which can make it easier to start many queries at once.
Both are available in WebUI, Command line, API and Clients
来源:https://stackoverflow.com/questions/50334775/does-bigquery-support-execute-immediate-command-to-run-dynamic-query