dbt

Write dbt test for positive values


Is there an easy way to write a test for a column being positive in dbt?

accepted_values doesn't seem to work for continuous variables.

I know you can write queries in ./tests but it looks like an overkill for such a simple thing.


Solution

  • You could use dbt_utils.expression_is_true

    version: 2
    
    models:
      - name: model_name
        tests:
          - dbt_utils.expression_is_true:
              expression: "col_a > 0"