Skip to content

Instantly share code, notes, and snippets.

@StuffbyYuki
Created April 5, 2022 14:46
Show Gist options
  • Save StuffbyYuki/c2ed822c87fb9efc037bc569128b8cc1 to your computer and use it in GitHub Desktop.
Save StuffbyYuki/c2ed822c87fb9efc037bc569128b8cc1 to your computer and use it in GitHub Desktop.
dbt jinja - store a query result in a variable
// source website
// https://stackoverflow.com/questions/64007239/hi-how-do-we-define-select-statement-as-a-variable-in-dbt
{%- call statement('my_statement', fetch_result=True) -%}
SELECT my_field FROM my_table
{%- endcall -%}
{%- set my_var = load_result('my_statement')['data'][0][0] -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment