don't allow duplicate col names in create table

This commit is contained in:
Pavan-Nambi
2025-10-09 08:09:31 +05:30
parent f06ee571be
commit f138448da2
2 changed files with 18 additions and 0 deletions

View File

@@ -40,6 +40,19 @@ pub fn translate_create_table(
bail_parse_error!("TEMPORARY table not supported yet");
}
// maybe we can do better than this.
if let ast::CreateTableBody::ColumnsAndConstraints { columns, .. } = &body {
for i in 0..columns.len() {
let name1 = normalize_ident(columns[i].col_name.as_str());
for j in (i + 1)..columns.len() {
let name2 = normalize_ident(columns[j].col_name.as_str());
if name1 == name2 {
bail_parse_error!("duplicate column name: {}", columns[i].col_name.as_str());
}
}
}
}
// Check for STRICT mode without experimental flag
if let ast::CreateTableBody::ColumnsAndConstraints { options, .. } = &body {
if options.contains(ast::TableOptions::STRICT) && !connection.experimental_strict_enabled()

View File

@@ -53,3 +53,8 @@ do_execsql_test_on_specific_db {:memory:} col-named-rowid {
update t set rowid = 1; -- should allow regular update and not throw unique constraint
select count(*) from t where rowid = 1;
} {3}
# https://github.com/tursodatabase/turso/issues/3637
do_execsql_test_in_memory_any_error create_table_duplicate_column_names {
CREATE TABLE t(a, a);
}