-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-1613] Update redshift adapter to use constraints and checks #227
Comments
Postgres example: {% macro postgres__create_table_as(temporary, relation, sql) -%}
{%- set unlogged = config.get('unlogged', default=false) -%}
{%- set sql_header = config.get('sql_header', none) -%}
{{ sql_header if sql_header is not none }}
{# Verify global macro is dispatched and can be overridden elegantly in any adapter(I can do this by creating a custom macro in the dbt-postgres equivalent adapter) #}
create {% if temporary -%}
temporary
{%- elif unlogged -%}
unlogged
{%- endif %} table {{ relation }}
{{ get_columns_spec_ddl() }}
as (
{{ sql }}
);
{%- endmacro %} |
howdy @sungchun12 ! did a bit of spelunking and came up with the following findings (from least to most pertinent):
The docs for create table examples show constraints as a part of the DDL, and behave as expected. The docs for this works: create table
"ci"."dbt_dconnors"."test_table__dbt_tmp"
(
id ,
color ,
date_day
)
as (
select 1 as id, 'red' as color, cast('2022-05-05' as date) as date_day
union all
select 2 as id, 'blue' as color, cast('2022-05-05' as date) as date_day
union all
select 3 as id, 'green' as color, cast('2022-05-05' as date) as date_day
); but this does not create table
"ci"."dbt_dconnors"."test_table__dbt_tmp"
(
id integer ,
color string ,
date_day date
)
as (
select 1 as id, 'red' as color, cast('2022-05-05' as date) as date_day
union all
select 2 as id, 'blue' as color, cast('2022-05-05' as date) as date_day
union all
select 3 as id, 'green' as color, cast('2022-05-05' as date) as date_day
); |
@dave-connors-3 Thanks for the detailed progress update! I may have a simple solution for you. I encountered the same problems in the postgres adapter. I got the below DDL work with the following macro. create table constraints
(
id integer not null primary key check (id > 0) ,
color text ,
date_day date
)
;
insert into constraints
(
id ,
color ,
date_day
)
(
select
1 as id,
'blue' as color,
cast('2019-01-01' as date) as date_day
); {% macro postgres__create_table_as(temporary, relation, sql) -%}
{%- set unlogged = config.get('unlogged', default=false) -%}
{%- set sql_header = config.get('sql_header', none) -%}
{{ sql_header if sql_header is not none }}
{% if config.get('constraints_enabled', False) %}
create {% if temporary -%}
temporary
{%- elif unlogged -%}
unlogged
{%- endif %} table {{ relation }}
{{ get_columns_spec_ddl() }} ;
insert into {{ relation }} {{ get_column_names() }}
(
{{ sql }}
);
{% else %}
create {% if temporary -%}
temporary
{%- elif unlogged -%}
unlogged
{%- endif %} table {{ relation }}
as (
{{ sql }}
);
{% endif %}
{%- endmacro %}
|
Can you link your PR branch to this issue? |
Use the new constraints configs from this PR: dbt-labs/dbt-core#6271
Reference dbt-snowflake PR doing something similar: dbt-labs/dbt-snowflake#341
Considerations
{{ get_columns_spec_ddl() }}
within the existing table materialization macro in redshift's adapter to get it workingdbt-constraints
branch from the PR to ensure this version ofdbt-core
works well with your PR branchThe text was updated successfully, but these errors were encountered: