Skip to content
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

[PostgreSQL] ERROR: adding primary key to a partitioned table is not yet implemented #612

Open
sanyamsinghal opened this issue Nov 22, 2022 · 1 comment
Assignees

Comments

@sanyamsinghal
Copy link
Collaborator

sanyamsinghal commented Nov 22, 2022

If we have a Partitioned Table in which PRIMARY KEY is added later on using ALTER TABLE then it fails with the following error:

ERROR: adding primary key to a partitioned table is not yet implemented (SQLSTATE XX000)

Workaround: Add PRIMARY KEY in the CREATE TABLE statement and remove corresponding ALTER TABLE statement.

Sample Exported Schema:

CREATE TABLE public.sales_region (
    id integer NOT NULL,
    amount integer,
    branch text,
    region text NOT NULL
)
PARTITION BY LIST (region);

ALTER TABLE ONLY public.sales_region ADD CONSTRAINT sales_region_pkey PRIMARY KEY (id, region);

Suggested Changes:

CREATE TABLE public.sales_region (
    id integer NOT NULL,
    amount integer,
    branch text,
    region text NOT NULL,
    PRIMARY KEY(id, region)
)
PARTITION BY LIST (region);
@sanyamsinghal sanyamsinghal self-assigned this Nov 22, 2022
@github-actions github-actions bot added the triage Needs to be triaged label Nov 22, 2022
@sanyamsinghal sanyamsinghal removed the triage Needs to be triaged label Nov 23, 2022
@sanyamsinghal sanyamsinghal changed the title [PostgreSQL] Getting ERROR: adding primary key to a partitioned table is not yet implemented [PostgreSQL] ERROR: adding primary key to a partitioned table is not yet implemented Nov 23, 2022
sanyamsinghal pushed a commit that referenced this issue Nov 23, 2022
…' statements to reduce occurences of error in #612
sanyamsinghal pushed a commit that referenced this issue Nov 23, 2022
…' statements to reduce occurences of error in #612
sanyamsinghal added a commit that referenced this issue Nov 28, 2022
@mrajcevic01
Copy link

I had initially created a new GH issue for this, not knowing one already existed - #1285

There have been additional users who have run into issues with the way we export schema into two different DDLs (CREATE TABLE & ALTER TABLE...ADD CONSTRAINT...PRIMARY KEY) . I have added the examples in the issue I created above but will re-iterate here:

  1. Creating the table with the primary key is faster than creating the table and then later changing the primary key, causing longer import times.
  2. We get an error when trying to migrate a table that needs to be partitioned on the target. This is a process specific to taking an existing application and making changes for it be geo-partitioned. (meaning it was not partitioned on the source but instead we edit the SQL file after the export so that it will be partitioned on the target). The error below:

x_restore_multi_region=# ALTER TABLE ONLY public.account_values ADD CONSTRAINT account_values_pkey PRIMARY KEY (id); ERROR: insufficient columns in PRIMARY KEY constraint definition DETAIL: PRIMARY KEY constraint on table "account_values" lacks column "geo_location" which is part of the partition key. x_restore_multi_region=# ALTER TABLE ONLY public.account_values ADD CONSTRAINT account_values_pkey PRIMARY KEY (id,geo_location); ERROR: changing primary key of a partitioned table is not yet implemented HINT: See https://github.com/yugabyte/yugabyte-db/issues/16980. React with thumbs up to raise its priority

We can avoid both of these by creating the PRIMARY KEY as part of the CREATE TABLE syntax as shown in our examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants