Home > Enterprise >  How can I improve the performance of multiple SQL queries from dbt to Snowflake?
How can I improve the performance of multiple SQL queries from dbt to Snowflake?

Time:08-17

Within my dbt scripts I need to run a few SQL commands that don't need to feed into something else (for example db cloning, permission setting, etc).

How can I improve the performance of running multiple little queries?

CodePudding user response:

In your dbt model, you can use a anonymous block. This allows you to run multiple queries inside of a single call.

To do this, use run_query with dbt, surrounding your code with begin and ending with end; $$.

Example:

{% set query %}
    begin
    -- lots of queries that don't really do anything special here, like db cloning or whatever --
    select 1;
    select 2;
    select 3;
    end;
    $$
{% endset %}
{% do run_query(query) %}
  • Related