Skip to content

Conversation

@RS2007
Copy link
Contributor

@RS2007 RS2007 commented Nov 29, 2025

Fixes #4029

turso> CREATE TABLE t (
    n REAL
);

CREATE TABLE t1 (
    m TEXT,
    d REAL
);

CREATE TRIGGER trg
BEFORE DELETE ON t
BEGIN
    UPDATE t1
    SET m = 'x'
    WHERE m = 'y';
END;

ALTER TABLE t1 DROP COLUMN m;
  × Runtime error: error in trigger trg after drop column: no such column: m

@Pavan-Nambi
Copy link
Contributor

Pavan-Nambi commented Nov 29, 2025

Hi,
no, the tests are correct i think,
if trigger is on same table as dropping col - no error - test case
if trigger on diff table - error

EDIT:

refer:https://github.com/sqlite/sqlite/blob/9b10698cc7dbe8fdbc29a36cdf9ac2b1f348cdc5/src/alter.c#L2194C1-L2263C65 - we rewrite and reload

or run test statements in sqlite.

} {
"CREATE TABLE s (a, b, FOREIGN KEY (b) REFERENCES t(a, c))"
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could u please move this test to triggers or anywhere else , - ideally to a file present in all.test
we don't test this file against sqlite for compatibility

refer: https://discord.com/channels/1258658826257961020/1265743446828781669/1441391189109637182

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this to alter_table.test

CREATE TRIGGER trg BEFORE DELETE ON t BEGIN UPDATE t1 SET m = 'x' WHERE m = 'y'; END;
ALTER TABLE t1 DROP COLUMN m;
} {
"Runtime error: error in trigger trg after drop column: no such column: m"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are expecting a error, u can just use do_execsql_test_in_memory_any_error

@RS2007
Copy link
Contributor Author

RS2007 commented Nov 30, 2025

Hi, no, the tests are correct i think, if trigger is on same table as dropping col - no error - test case if trigger on diff table - error

EDIT:

refer:https://github.com/sqlite/sqlite/blob/9b10698cc7dbe8fdbc29a36cdf9ac2b1f348cdc5/src/alter.c#L2194C1-L2263C65 - we rewrite and reload

or run test statements in sqlite.

Isn't the way that we do better, i can just exclude the case where the trigger is on the same table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't allow dropping column if trigger referencing it

2 participants