From f138448da2ba39876c01b0d5d1a92cedfc054fb2 Mon Sep 17 00:00:00 2001 From: Pavan-Nambi Date: Thu, 9 Oct 2025 08:09:31 +0530 Subject: [PATCH] don't allow duplicate col names in create table --- core/translate/schema.rs | 13 +++++++++++++ testing/create_table.test | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/core/translate/schema.rs b/core/translate/schema.rs index a78e1b630..f7fde9f51 100644 --- a/core/translate/schema.rs +++ b/core/translate/schema.rs @@ -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() diff --git a/testing/create_table.test b/testing/create_table.test index 7eb7bea7d..e961c017f 100755 --- a/testing/create_table.test +++ b/testing/create_table.test @@ -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); +} \ No newline at end of file