diff --git a/pkg/sql/logictest/testdata/logic_test/create_table b/pkg/sql/logictest/testdata/logic_test/create_table index ff3b38f8bfcb..f6aa3ea764fe 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_table +++ b/pkg/sql/logictest/testdata/logic_test/create_table @@ -1039,3 +1039,30 @@ public generated_by_default_t_notnull_b_seq INT8 public generated_always_t_notnull_b_seq INT8 public generated_by_default_t_b_seq INT8 public generated_always_t_b_seq INT8 + +subtest end + +# This subtest ensures we can create not valid unique-without-index constraint +# during table creation, which will be treated as a "normal" +# unique-without-index constraint (meaning the NOT VALID will be dropped). +subtest 115352 + +statement ok +SET experimental_enable_unique_without_index_constraints = true + +statement ok +CREATE TABLE t_115352 (i INT, UNIQUE WITHOUT INDEX (i) NOT VALID); + +# NOT VALID constraint specified within `CREATE TABLE` is a no-op and does not +# skip validation. +query T +SELECT create_statement FROM [SHOW CREATE t_115352]; +---- +CREATE TABLE public.t_115352 ( + i INT8 NULL, + rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(), + CONSTRAINT t_115352_pkey PRIMARY KEY (rowid ASC), + CONSTRAINT unique_i UNIQUE WITHOUT INDEX (i) +) + +subtest end diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 680efe416f60..38917a28042c 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -9821,7 +9821,7 @@ table_elem: { def := $1.constraintDef() valBehavior := $2.validationBehavior() - if u, ok := def.(*tree.UniqueConstraintTableDef); ok && valBehavior == tree.ValidationSkip { + if u, ok := def.(*tree.UniqueConstraintTableDef); ok && valBehavior == tree.ValidationSkip && !u.WithoutIndex { typ := "PRIMARY KEY" if !u.PrimaryKey { typ = "UNIQUE"