dbt-labs / dbt-labs/docs.getdbt.com
Explain early-binding views in Postgres and include our pro-tips
- Dominant language
- JavaScript
- Stars
- 215
- Forks
- 1.2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 130
Description
### Contributions
- [X] I have read the contribution docs, and understand what's expected of me.
### Link to the page on docs.getdbt.com requiring updates
https://docs.getdbt.com/reference/resource-configs/postgres-configs
### What part(s) of the page would you like to see updated?
Add new section called "Early binding views" between "Performance optimizations" and "Materialized views", just like the [docs for dbt-redshift](https://docs.getdbt.com/reference/resource-configs/redshift-configs#late-binding-views).
The new context might look like this:
```markdown
### Early binding views
Unlike Redshift, Postgres does not support [views](https://docs.getdbt.com/terms/view) unbound from their dependencies ([late binding views](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_VIEW.html#late-binding-views)). In practice, this means that if upstream views or tables are dropped with a cascade qualifier, any view that depends on it will get dropped as well.
To avoid having data that is unavailable to consumers during a dbt build, our recommendation is to use the [`table` materialization](https://docs.getdbt.com/docs/build/materializations#table) for any relations that are exposed to consumers.
```
### Key insight
When a table is recreated in Postgres, any views that depend upon it will be deleted automatically and will need to be recreated. They will be unavailable in the meantime and data access attempts will return a database error.
This is because postgres only supports early-binding views (as opposed to most other cloud data warehouses). As a derivative of Postgres, Redshift also uses early-binding views, but it allows [late-binding](https://aws.amazon.com/about-aws/whats-new/2017/09/amazon-redshift-now-supports-late-binding-views-referencing-amazon-redshift-and-redshift-spectrum-external-tables/) as a configuration option. BigQuery, Spark, and Databricks only have late-binding views.
### Our recommendations
- In Redshift, use [late-binding views](https://docs.getdbt.com/reference/resource-configs/redshift-configs#late-binding-views) across the board
- In Postgres, use [tables](https://docs.getdbt.com/docs/build/materializations#table) (rather than [views](https://docs.getdbt.com/docs/build/materializations#view)) for any data sets that are exposed to consumers
### Additional information
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.