Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ca3dfcb
placeholder outline
sungchun12 Dec 19, 2022
9bb5245
add version blocks
sungchun12 Dec 19, 2022
99673b8
add to sidebar
sungchun12 Dec 19, 2022
4dc1c09
remove version blocks
sungchun12 Dec 19, 2022
1dea692
add 2 sections
sungchun12 Dec 19, 2022
ddeae87
postgres section example
sungchun12 Dec 19, 2022
8b5f874
add more docs
sungchun12 Dec 19, 2022
8788c7c
correct DDL
sungchun12 Dec 19, 2022
56004bd
correct config name
sungchun12 Dec 19, 2022
6fc8c70
fix data type
sungchun12 Dec 19, 2022
6e93abe
add redshift docs
dave-connors-3 Dec 21, 2022
769053e
Update constraints docs for Snowflake
b-per Dec 21, 2022
08daa11
Merge branch 'dbt-constraints-docs' of github.com:dbt-labs/docs.getdb…
b-per Dec 21, 2022
bff560e
Merge branch 'current' of https://github.com/dbt-labs/docs.getdbt.com…
sungchun12 Jan 3, 2023
bcdc1fa
add model config links
sungchun12 Jan 3, 2023
2d04d37
update warehouse to spark
sungchun12 Jan 3, 2023
63475b8
update not null syntax
sungchun12 Jan 3, 2023
2b0fc9e
add more config examples
sungchun12 Jan 4, 2023
c33f705
fix ordering
sungchun12 Jan 4, 2023
dc6634f
update docs based on new parsing
sungchun12 Jan 9, 2023
e295c43
add a note
sungchun12 Jan 17, 2023
181a07d
add example error messages
sungchun12 Feb 3, 2023
82a4752
Update config name on Redshift
b-per Feb 3, 2023
1df2052
Update description for Spark
b-per Feb 3, 2023
f97d987
add explainers
sungchun12 Feb 16, 2023
92eb51c
add check
sungchun12 Feb 16, 2023
b0243ff
remove fluff
sungchun12 Feb 16, 2023
f98639a
Merge branch 'current' into dbt-constraints-docs
sungchun12 Feb 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update constraints docs for Snowflake
  • Loading branch information
b-per committed Dec 21, 2022
commit 769053e9dacdbfd6233e3704ac90b8c6ad17b0f4
79 changes: 77 additions & 2 deletions website/docs/reference/resource-configs/constraints_enabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,83 @@ models:

<div warehouse="Snowflake">

* dbt accounts for the [`copy_grants` configuration](/reference/resource-configs/snowflake-configs#copying-grants) when calculating which grants need to be added or removed.
- Snowflake constraints documentation: [here](https://docs.snowflake.com/en/sql-reference/constraints-overview.html)
- Snowflake data types: [here](https://docs.snowflake.com/en/sql-reference/intro-summary-data-types.html)

Snowflake suppports four types of constraints: `unique`, `not null`, `primary key` and `foreign key`.

It is important to note that only the `not null` (and the `not null` property of `primary key`) are actually checked today.
There rest of the constraints are purely metadata, not verified when inserting data.

Currently, Snowflake doesn't support the `check` syntax and dbt will skip the `check` config and raise a warning message if it is set on some models in the dbt project.

<File name='models/constraints_example.sql'>

```sql
{{
config(
materialized = "table"
)
}}

select
1 as id,
'blue' as color,
cast('2019-01-01' as date) as date_day
```

</File>

<File name='models/schema.yml'>

```yml
models:
- name: constraints_example
docs:
node_color: black
config:
constraints_enabled: true
columns:
- name: id
data_type: integer
description: hello
constraints: ['not null','primary key']
tests:
- unique
- name: color
data_type: text
- name: date_day
data_type: date
```

</File>

Expected DDL to enforce constraints:
<File name='target/run/.../constraints_example.sql'>

```sql
create or replace transient table AD_HOC.dbt_bperigaud.constraints_model


(

id integer not null primary key ,
color text ,
date_day date
)


as
(

select
1 as id,
'blue' as color,
cast('2019-01-01' as date) as date_day
);
```

</File>

</div>

Expand Down Expand Up @@ -164,7 +240,6 @@ models:
data_type: integer
description: hello
constraints: ['not null','primary key']
check: (id > 0)
tests:
- unique
- name: color
Expand Down