Skip to content

Commit

Permalink
Handle >64 characters partition names
Browse files Browse the repository at this point in the history
  • Loading branch information
ggam committed May 1, 2024
1 parent 23a0854 commit dbd2a9a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions dbt/include/postgres/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,17 @@
{% set existing_partitions_query %}
select
inhrelid::regclass::text as from_table_name,
replace(
inhrelid::regclass::text,
'{{ from_relation.schema }}.{{ from_relation.identifier }}', -- Current partition name
'{{ to_relation.identifier }}' -- New partition name
) as to_table_name
regexp_substr(inhrelid::regclass::text, '[^_]*$') as partition_suffix -- Get the string after the last underscore
from pg_catalog.pg_inherits
where inhparent = '{{ from_relation.schema }}.{{ from_relation.identifier }}'::regclass;
{% endset %}
{% set existing_partitions_results = run_query(existing_partitions_query) %}

-- Rename the existing partitions
{% for existing_partition in existing_partitions_results.rows %}
alter table {{ existing_partition["from_table_name"] }} rename to {{ existing_partition["to_table_name"] }};
{%- set partition_relation = make_intermediate_relation(to_relation, existing_partition['partition_suffix']) %}

alter table {{ existing_partition["from_table_name"] }} rename to {{ partition_relation.identifier }};
{% endfor %}
{%- endcall %}
{% endmacro %}
Expand Down

0 comments on commit dbd2a9a

Please sign in to comment.