diff --git a/core/translate/alter.rs b/core/translate/alter.rs index d3170fdbe..c07781f35 100644 --- a/core/translate/alter.rs +++ b/core/translate/alter.rs @@ -207,6 +207,13 @@ pub fn translate_alter_table( } } + let new_column_name = column.name.as_ref().unwrap(); + if btree.get_column(new_column_name).is_some() { + return Err(LimboError::ParseError( + "duplicate column name: ".to_string() + new_column_name, + )); + } + // TODO: All quoted ids will be quoted with `[]`, we should store some info from the parsed AST btree.columns.push(column.clone()); diff --git a/testing/alter_table.test b/testing/alter_table.test index e9e83c403..26f79cd67 100755 --- a/testing/alter_table.test +++ b/testing/alter_table.test @@ -133,6 +133,17 @@ do_execsql_test_in_memory_any_error fail-alter-table-drop-unique-column-constrai ALTER TABLE t DROP b; } + +# refer https://github.com/tursodatabase/turso/issues/3231 +do_execsql_test_in_memory_any_error fail-alter-table-add-duplicate-column { + CREATE TABLE t1 (a); + ALTER TABLE t1 ADD COLUMN a; +} +do_execsql_test_in_memory_any_error fail-alter-table-add-duplicate-column-case-insensitive { + CREATE TABLE t1 (a); + ALTER TABLE t1 ADD COLUMN A; +} + do_execsql_test_in_memory_any_error fail-alter-table-drop-primary-key-column { CREATE TABLE t (a PRIMARY KEY, b); ALTER TABLE t DROP a;