# Limiting the not\_null test

**URL:** https://discourse.getdbt.com/t/limiting-the-not-null-test/2694
**Category:** Help
**Tags:** testing, best-practice
**Created:** [June 29, 2021, 8:57pm UTC](https://discourse.getdbt.com/t/limiting-the-not-null-test/2694 "2021-06-29T20:57:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://discourse.getdbt.com/u/rob)
#### Post date: [June 29, 2021, 8:57pm UTC](https://discourse.getdbt.com/t/limiting-the-not-null-test/2694/1 "2021-06-29T20:57:25Z")

</div>

This question was [posed in Slack in 2019](https://getdbt.slack.com/archives/C2JRRQDTL/p1568186744302000):

> When running schema tests, such as `not_null`, the SQL is executed over the entire table. As the table grows in size the cost of running such tests increases… Is there a way to limit the schema tests to the partition of data that was inserted on the current `run` ?

One proposed solution was “write a custom test that only filters on the latest [data].”

What’s the best practice?

---

<div class="post-metadata">

### Author: ![joellabes](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/joellabes/32/3980_2.png) [@joellabes](https://discourse.getdbt.com/u/joellabes)
#### Post date: [July 16, 2021, 9:37am UTC](https://discourse.getdbt.com/t/limiting-the-not-null-test/2694/2 "2021-07-16T09:37:58Z")

</div>

As of dbt 0.20.0, you can include a `where` clause in your test config! Here’s an example from the docs: [where | dbt Docs](https://docs.getdbt.com/reference/resource-configs/where)

If you’re not able to upgrade yet, earlier versions of dbt-utils have a [not\_null\_where](https://github.com/dbt-labs/dbt-utils/tree/0.6.6#not_null_where-source) test you can use instead.

---

<div class="post-metadata">

### Author: ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://discourse.getdbt.com/u/rob)
#### Post date: [July 16, 2021, 12:29pm UTC](https://discourse.getdbt.com/t/limiting-the-not-null-test/2694/3 "2021-07-16T12:29:26Z")

</div>

Great. Thanks @joellabes

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)
#### Post date: [October 23, 2022, 12:19am UTC](https://discourse.getdbt.com/t/limiting-the-not-null-test/2694/4 "2022-10-23T00:19:52Z")

</div>

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