-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: improve pk error messaging when using interleave tables #45537
Copy link
Copy link
Closed
Labels
A-schema-changesA-sql-interleavedC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Description
Consider this example with three tables. You can't alter the middle relationship because the bottom table is interleaved but this is confusing to the user because they are trying to remove the interleaving relationship with the top and middle tables:
root@127.0.0.1:62260/movr> CREATE TABLE customers (
id INT PRIMARY KEY,
name STRING(50)
);
CREATE TABLE
Time: 2.977ms
root@127.0.0.1:62260/movr> CREATE TABLE orders (
customer INT,
id INT,
total DECIMAL(20, 5),
PRIMARY KEY (customer, id),
CONSTRAINT fk_customer FOREIGN KEY (customer) REFERENCES customers
) INTERLEAVE IN PARENT customers (customer);
CREATE TABLE
Time: 9.277ms
root@127.0.0.1:62260/movr> CREATE TABLE packages (
customer INT,
"order" INT,
id INT,
address STRING(50),
delivered BOOL,
delivery_date DATE,
PRIMARY KEY (customer, "order", id),
CONSTRAINT fk_order FOREIGN KEY (customer, "order") REFERENCES orders
) INTERLEAVE IN PARENT orders (customer, "order");
CREATE TABLE
Time: 10.423ms
root@127.0.0.1:62260/movr> set experimental_enable_primary_key_changes =true;
SET
Time: 257µs
root@127.0.0.1:62260/movr> ALTER TABLE orders ALTER PRIMARY KEY USING COLUMNS (id);
ERROR: cannot change the primary key of an interleaved parentWe could improve this error message to read something like:
ERROR: cannot change the primary key of orders because table packages is interleaved into it
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-changesA-sql-interleavedC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)