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 vatiables.
I know you can write queries in ./tests
but it looks like an overkill for such a simple thing.
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 vatiables.
I know you can write queries in ./tests
but it looks like an overkill for such a simple thing.
You could use dbt_utils.expression_is_true
version: 2
models:
- name: model_name
tests:
- dbt_utils.expression_is_true:
expression: "col_a > 0"
I think the dbt_utils suggestion is good, the only reasonable alternative I can think of is writing a custom schema test:
https://docs.getdbt.com/docs/guides/writing-custom-schema-tests/
But why bother when you can just use expression_is_true @jake
Previous answer is correct. Another option is accepted_range:
version: 2
models:
- name: model_name
columns:
- name: user_id
tests:
- dbt_utils.accepted_range:
min_value: 0
inclusive: false