Scalar Value to a Variables

Hi All,

I am new to DBT, and trying to fetch the count of a table and use it as a variable. I wrote the below code and I get the compilation error.

{% set cnt=run_query(‘select count(*) from jobdata’) %}

{{ log("got " ~ cnt[0][0], info=true) }}

this model gives me the error - ‘None’ has no attribute ‘table’ Can you please help?

Try this way:
{% set cnt=run_query(‘select count(*) from jobdata’).columns[0][0] %}

2 Likes