Skip to content

Commit

Permalink
Merge #40965
Browse files Browse the repository at this point in the history
40965: sql: fix behavior of SERIAL columns on mixed-case tables r=jordanlewis a=jordanlewis

Closes #40964.

When `experimental_serial_normalization` is set to `sql_sequence`, there
was previously an issue with mixed-case tables - the created sequence
wouldn't be quoted properly. This fixes the issue.

Release note (sql change): fix behavior of SERIAL columns on mixed-case
tables when experimental_serial_normalization=sql_sequence.
Release justification: low-risk bugfix.

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Sep 23, 2019
2 parents 17421f4 + 7cdfbc1 commit 9dd1564
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/serial
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,26 @@ SELECT count(DISTINCT a), count(DISTINCT b), count(DISTINCT c) FROM serial
----
4 3 4

statement ok
CREATE TABLE "serial_MixedCase" (
a SERIAL PRIMARY KEY,
b INT DEFAULT 7,
c SERIAL,
UNIQUE INDEX (c)
)

query TT
SHOW CREATE TABLE "serial_MixedCase"
----
"serial_MixedCase" CREATE TABLE "serial_MixedCase" (
a INT8 NOT NULL DEFAULT nextval('"serial_MixedCase_a_seq"':::STRING),
b INT8 NULL DEFAULT 7:::INT8,
c INT8 NOT NULL DEFAULT nextval('"serial_MixedCase_c_seq"':::STRING),
CONSTRAINT "primary" PRIMARY KEY (a ASC),
UNIQUE INDEX "serial_MixedCase_c_key" (c ASC),
FAMILY "primary" (a, b, c)
)

statement error multiple default values specified for column "a" of table "s1"
CREATE TABLE s1 (a SERIAL DEFAULT 7)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (p *planner) processSerialInColumnDef(

defaultExpr := &tree.FuncExpr{
Func: tree.WrapFunction("nextval"),
Exprs: tree.Exprs{tree.NewStrVal(seqName.Table())},
Exprs: tree.Exprs{tree.NewStrVal(seqName.String())},
}

seqType := ""
Expand Down

0 comments on commit 9dd1564

Please sign in to comment.