dbt-labs / redshift

Redshift package for dbt (getdbt.com)
https://hub.getdbt.com/dbt-labs/redshift/latest/
Apache License 2.0
99 stars 41 forks source link

NOT NULL redshift constraint #38

Open misteliy opened 4 years ago

misteliy commented 4 years ago

Describe the feature

not null constraints are enforced by redshift. Hence it would be good to have a mechanism to enable them within the dbt framework

Describe alternatives you've considered

we created a post-hook macro that looks something like this: ALTER TABLE {{ this }} ADD COLUMN Temp varchar(32) not null default ''; UPDATE {{ this }} SET Temp = {{ column }}; ALTER TABLE {{ this }} DROP COLUMN {{ column }}; ALTER TABLE {{ this }} RENAME COLUMN Temp TO {{ column }};

Therefore creating a temp column, then copy, then drop the original and then rename. This is a very ugly hack and has also the problem that you need to specify a default value in the alter table command :/

Who will this benefit?

for all the redshift users it would be nice to leverage the constraint capabilities if enforced and hence this could be a nice add on.

yummydum commented 2 years ago

Are there plans for this feature? It would be nice to have other constraints such as primary key and foreign key as well.

ajaymalikbol commented 1 month ago

Are there plans for this feature? It would be nice to have other constraints such as primary key and foreign key as well.

No

misteliy commented 1 month ago

Hmm, I think these topics should be discussed in the bigger context of data contracts, otherwise the contract features won’t be really useful. I think there might also be options to rethink as contracts and dbt tests somewhat are doing overlapping activities. I would prefer to define contracts and tests in a unified way…