Skip to content

Commit d015119

Browse files
committed
tree: fix formatting of ON COMMIT PRESERVE ROWS
Formatting for this clause was added in d80409c, but that had a mistake since the locality clause should always be formatted after the ON COMMIT clause. Release note: None
1 parent 1522360 commit d015119

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

pkg/sql/parser/testdata/create_table

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,3 +2687,19 @@ CREATE TABLE t (l LTREE) -- normalized!
26872687
CREATE TABLE t (l LTREE) -- fully parenthesized
26882688
CREATE TABLE t (l LTREE) -- literals removed
26892689
CREATE TABLE _ (_ LTREE) -- identifiers removed
2690+
2691+
parse
2692+
CREATE TABLE tbl (a INT PRIMARY KEY) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION
2693+
----
2694+
CREATE TABLE tbl (a INT8 PRIMARY KEY) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION -- normalized!
2695+
CREATE TABLE tbl (a INT8 PRIMARY KEY) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION -- fully parenthesized
2696+
CREATE TABLE tbl (a INT8 PRIMARY KEY) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION -- literals removed
2697+
CREATE TABLE _ (_ INT8 PRIMARY KEY) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION -- identifiers removed
2698+
2699+
error
2700+
CREATE TABLE tbl AS (SELECT * FROM t) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION
2701+
----
2702+
at or near "locality": syntax error
2703+
DETAIL: source SQL:
2704+
CREATE TABLE tbl AS (SELECT * FROM t) ON COMMIT PRESERVE ROWS LOCALITY REGIONAL BY TABLE IN PRIMARY REGION
2705+
^

pkg/sql/sem/tree/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,10 +1581,6 @@ func (node *CreateTable) FormatBody(ctx *FmtCtx) {
15811581
ctx.FormatNode(&node.StorageParams)
15821582
ctx.WriteByte(')')
15831583
}
1584-
if node.Locality != nil {
1585-
ctx.WriteString(" ")
1586-
ctx.FormatNode(node.Locality)
1587-
}
15881584
}
15891585
switch node.OnCommit {
15901586
case CreateTableOnCommitUnset:
@@ -1593,6 +1589,10 @@ func (node *CreateTable) FormatBody(ctx *FmtCtx) {
15931589
default:
15941590
panic(errors.AssertionFailedf("unexpected CreateTableOnCommitSetting: %d", node.OnCommit))
15951591
}
1592+
if node.Locality != nil {
1593+
ctx.WriteString(" ")
1594+
ctx.FormatNode(node.Locality)
1595+
}
15961596
}
15971597

15981598
// HoistConstraints finds column check and foreign key constraints defined

pkg/sql/sem/tree/pretty.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,16 +1302,16 @@ func (node *CreateTable) doc(p *PrettyCfg) pretty.Doc {
13021302
),
13031303
)
13041304
}
1305-
if node.Locality != nil {
1306-
clauses = append(clauses, p.Doc(node.Locality))
1307-
}
13081305
switch node.OnCommit {
13091306
case CreateTableOnCommitUnset:
13101307
case CreateTableOnCommitPreserveRows:
13111308
clauses = append(clauses, pretty.Keyword("ON COMMIT PRESERVE ROWS"))
13121309
default:
13131310
panic(errors.AssertionFailedf("unexpected CreateTableOnCommitSetting: %d", node.OnCommit))
13141311
}
1312+
if node.Locality != nil {
1313+
clauses = append(clauses, p.Doc(node.Locality))
1314+
}
13151315
if len(clauses) == 0 {
13161316
return title
13171317
}

0 commit comments

Comments
 (0)