-
-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
Describe the bug
When a column with FK is dropped using DROP COLUMN the constraint is not dropped properly. After that, the DELETE query throws an error column "table.column_name" does not exist". This error can be avoided if you delete the constraint manually by ALTER TABLE "table" DROP CONSTRAINT IF EXISTS "column_fk";.
To Reproduce
This script
CREATE TABLE "parent" ("id" INTEGER PRIMARY KEY, "value" INTEGER);
CREATE TABLE "child" ("id" INTEGER PRIMARY KEY, "parent_id" INTEGER NOT NULL REFERENCES "parent"("id"));
INSERT INTO "parent"("id", "value") VALUES (1, 42);
INSERT INTO "child"("id", "parent_id") VALUES (1, 1);
ALTER TABLE "child" DROP COLUMN "parent_id";
DELETE FROM "parent" WHERE "id" = 1throws next error:
error: column "child.parent_id" does not exist
π This seems to be an execution error, which means that your request syntax seems okay,
but the resulting statement cannot be executed β Probably not a pg-mem error.
* Reconsituted failed SQL statement: DELETE FROM parent WHERE (id = (1)) ]
π You can file an issue at https://github.com/oguimbal/pg-mem along with a way to reproduce this error (if you can), and the stacktrace:
data: {
error: "column \"child.parent_id\" does not exist",
code: undefined,
},
code: undefined,
location: {
start: 0,
end: 0,
},
errorDetailsIncluded: true,
at _buildValueReal (/usr/src/src/parser/expression-builder.ts:91:19)
at _buildValue (/usr/src/src/parser/expression-builder.ts:51:11)
at buildBinary (/usr/src/src/parser/expression-builder.ts:276:21)
at _buildValue (/usr/src/src/parser/expression-builder.ts:51:11)
at buildValue (/usr/src/src/parser/expression-builder.ts:20:17)
at <anonymous> (/usr/src/src/transforms/build-filter.ts:22:23)
at usingValue (/usr/src/src/parser/context.ts:11:20)
at <anonymous> (/usr/src/src/constraints/foreign-key.ts:96:49)
at before (/usr/src/src/table.ts:418:25)
at delete (/usr/src/src/table.ts:491:20)
I submitted a testcase for this bug
#470
pg-mem version
"version": "3.0.5",
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels