pg_partman icon indicating copy to clipboard operation
pg_partman copied to clipboard

Issue with template pk when having it as index on parent

Open thecampagnards opened this issue 10 months ago • 0 comments

Hello, I have an issue using template pk and having this pk as index on the parent, eg:

CREATE TABLE example (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    issue_date timestamp with time zone NOT NULL
)
PARTITION BY RANGE(issue_date);
CREATE INDEX example_id_idx ON ONLY example USING btree (id);

CREATE TABLE example_template (LIKE example);
ALTER TABLE example_template ADD PRIMARY KEY ("id");

SELECT create_parent(p_parent_table := 'public.example', p_control := 'issue_date', p_interval := '1 year', p_template_table := 'public.example_template', p_premake := 1);
test9=# \d example
                        Partitioned table "public.example"
   Column   |           Type           | Collation | Nullable |      Default      
------------+--------------------------+-----------+----------+-------------------
 id         | uuid                     |           | not null | gen_random_uuid()
 issue_date | timestamp with time zone |           | not null | 
Partition key: RANGE (issue_date)
Indexes:
    "example_id_idx" btree (id)
test9=# \d example_template
                    Table "public.example_template"
   Column   |           Type           | Collation | Nullable | Default 
------------+--------------------------+-----------+----------+---------
 id         | uuid                     |           | not null | 
 issue_date | timestamp with time zone |           | not null | 
Indexes:
    "example_template_pkey" PRIMARY KEY, btree (id)
test9=# \d example_p20240101
                         Table "public.example_p20240101"
   Column   |           Type           | Collation | Nullable |      Default      
------------+--------------------------+-----------+----------+-------------------
 id         | uuid                     |           | not null | gen_random_uuid()
 issue_date | timestamp with time zone |           | not null | 
Partition of: example FOR VALUES FROM ('2024-01-01 00:00:00+00') TO ('2025-01-01 00:00:00+00')
Indexes:
    "example_p20240101_id_idx" btree (id)

It seems that it doesnt take into account the template pk because of the parent index on this pk. Is there something that I miss ?

Thx !!

thecampagnards avatar Jun 13 '25 16:06 thecampagnards