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

[YSQL] Dropping a primary key constraint is not supported #8735

Closed
radekg opened this issue Jun 2, 2021 · 8 comments
Closed

[YSQL] Dropping a primary key constraint is not supported #8735

radekg opened this issue Jun 2, 2021 · 8 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/high High Priority
Projects

Comments

@radekg
Copy link
Contributor

radekg commented Jun 2, 2021

Jira Link: DB-1677
Attempting dropping a primary key constraint results in an error:

Error: ERROR: dropping a primary key constraint is not yet supported [Failed SQL: ALTER TABLE public.TABLE_NAME DROP CONSTRAINT CONSTRAINT_2]

This is explicitly disabled in the code:

errmsg("dropping a primary key constraint is not yet supported")));
.

From what I hear, the reason is that the primary key is tied to the table's storage layout and this is remotely related to ALTER TABLE adding a primary key #1104. This seems like a reversal of fd257e7.

@ddorian ddorian added the area/ysql Yugabyte SQL (YSQL) label Jun 3, 2021
@frozenspider frozenspider added this to Backlog in YSQL via automation Jul 22, 2021
@frozenspider frozenspider self-assigned this Jul 22, 2021
@mskarbek
Copy link

+1 with Boundary:

"error": "postgres.(Postgres).EnsureVersionTable: unknown, unknown: error #0: ERROR: dropping a primary key constraint is not yet supported (SQLSTATE 0A000)",

@jimlambrt
Copy link

jimlambrt commented May 24, 2022

+1 for this capability. I'd like to run Boundary with yugabyte

@amitsaxena
Copy link

Is there a workaround if I want to change the primary key of a table? Haven't been able to find anything in the docs:
https://docs.yugabyte.com/preview/explore/indexes-constraints/primary-key-ysql/

@frozenspider
Copy link
Contributor

frozenspider commented May 27, 2022

@amitsaxena While this issue isn't implemented, you can do something like

CREATE TABLE t2 (...);
INSERT INTO t2 SELECT * FROM t;
DROP TABLE t;
ALTER TABLE t2 RENAME TO t;

This assumes you're just playing around and there are no real workloads using t

@radekg
Copy link
Contributor Author

radekg commented May 27, 2022

While this is a great insight, it’s not enough in many cases. This issue is still preventing installing keycloak on ybdb using default migrations.

@frozenspider
Copy link
Contributor

@radekg of course, this is merely a workaround. This issue is on our radars though.

@arunk-r
Copy link

arunk-r commented Jun 3, 2022

YugaByte DB Liquibase error for Keycloak.
Reason: liquibase.exception.DatabaseException: ERROR: dropping a primary key constraint is not yet supported [Failed SQL: (0) ALTER TABLE public.USER_REQUIRED_ACTION DROP CONSTRAINT CONSTRAINT_2]

@yugabyte-ci yugabyte-ci added kind/bug This issue is a bug priority/medium Medium priority issue labels Jun 8, 2022
@ymahajan ymahajan added priority/high High Priority and removed priority/medium Medium priority issue labels Jun 14, 2022
@frozenspider frozenspider moved this from Backlog to In progress in YSQL Jul 5, 2022
YSQL automation moved this from In progress to Done Jul 29, 2022
@frozenspider
Copy link
Contributor

This has been implemented.
Note that just like ALTER ADD PK, this is NOT an online operation, and is only expected to be used for a database setup. Concurrent DMLs to this table might be lost!
Making it online is tracked separately in #13274.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/high High Priority
Projects
Status: Done
YSQL
  
Done
Development

No branches or pull requests

9 participants