Data compare in IF condition in dbt model

I have to compare the result of query with hardcoded integer value in if condition

{%- set query %}
select cast(1 as integer)
{% endset -%}
{%- set main = run_query(query) -%}

{% if execute %}

{% if main > 2 %}

Getting below error…

'>' not supported between instances of 'Table' and 'int'

Hi @Bhrat123, the result of run_query is an Agate table, not an integer.

The Getting Started Guide has a section on using run_query effectively - I would recommend reviewing that as well!

Hi Bhrat123,

‘main’ variable in your code is of ‘table’ type, it doesn’t hold the value of your query result. Check run_query | dbt Docs for more details, especially ‘columns’ property.


1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.