-
-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Seems, you have some issues with partitioned tables (PostgreSQL 12.7)
On DB "postgres":
create database f1 ENCODING = 'UTF8';
create database f2 ENCODING = 'UTF8';
On DB "f1":
create table t1 ( id int , doy int ) partition by list ( doy )
create table t1_1 partition of t1 for values in ( 1 )
create table t1_2 partition of t1 for values in ( 2 )
alter table t1 add constraint pk_t1 primary key ( id, doy )
$ migra --unsafe postgresql:///f2 postgresql:///f1 > /tmp/t1.sql
t1.sql:
create table "public"."t1" (
"id" integer not null,
"doy" integer not null
) partition by LIST (doy);
create table "public"."t1_1" partition of "public"."t1" FOR VALUES IN (1);
create table "public"."t1_2" partition of "public"."t1" FOR VALUES IN (2);
CREATE UNIQUE INDEX pk_t1 ON ONLY public.t1 USING btree (id, doy);
CREATE UNIQUE INDEX t1_1_pkey ON public.t1_1 USING btree (id, doy);
CREATE UNIQUE INDEX t1_2_pkey ON public.t1_2 USING btree (id, doy);
alter table "public"."t1" add constraint "pk_t1" PRIMARY KEY using index "pk_t1";
alter table "public"."t1_1" add constraint "t1_1_pkey" PRIMARY KEY using index "t1_1_pkey";
alter table "public"."t1_2" add constraint "t1_2_pkey" PRIMARY KEY using index "t1_2_pkey";
$ psql -d f2 -f /tmp/t1.sql > /tmp/t1.log
psql:/tmp/t1.sql:19: ERROR: index "pk_t1" is not valid
LINE 1: alter table "public"."t1" add constraint "pk_t1" PRIMARY KEY...
Example (1):
create table t1 ( id int , doy int ) partition by list ( doy );
create table t1_1 partition of t1 for values in ( 1 );
create table t1_2 partition of t1 for values in ( 2 );
create unique index ix1 on ONLY t1 ( id, doy );
alter table t1 add constraint pk_t1 primary key using index ix1;
ERROR: index "ix1" is not valid
LINE 1: alter table t1 add constraint pk_t1 primary key using index ...
Example (2):
create table t1 ( id int , doy int ) partition by list ( doy );
create table t1_1 partition of t1 for values in ( 1 );
create table t1_2 partition of t1 for values in ( 2 );
create unique index ix1 on t1 ( id, doy );
alter table t1 add constraint pk_t1 primary key using index ix1;
ERROR: ALTER TABLE / ADD CONSTRAINT USING INDEX is not supported on partitioned tables
p.s.
"pg_dump" copies such schema (partitioned table + primary key) between DBs f1 and f2 with no issues