Skip to content

Commit

Permalink
Fix the format of CREATE INDEX statement (#228)
Browse files Browse the repository at this point in the history
* Fix format of (*CreateIndex).SQL()

* Update testdata

* Fix format
  • Loading branch information
apstndb authored Dec 18, 2024
1 parent 66dfc61 commit eccf53d
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 38 deletions.
36 changes: 10 additions & 26 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,32 +1027,16 @@ func (r *RenameTable) SQL() string { return "RENAME TABLE " + sqlJoin(r.Tos, ",
func (r *RenameTableTo) SQL() string { return r.Old.SQL() + " TO " + r.New.SQL() }

func (c *CreateIndex) SQL() string {
sql := "CREATE "
if c.Unique {
sql += "UNIQUE "
}
if c.NullFiltered {
sql += "NULL_FILTERED "
}
sql += "INDEX "
if c.IfNotExists {
sql += "IF NOT EXISTS "
}
sql += c.Name.SQL() + " ON " + c.TableName.SQL() + " ("
for i, k := range c.Keys {
if i != 0 {
sql += ", "
}
sql += k.SQL()
}
sql += ")"
if c.Storing != nil {
sql += " " + c.Storing.SQL()
}
if c.InterleaveIn != nil {
sql += c.InterleaveIn.SQL()
}
return sql
return "CREATE " +
strOpt(c.Unique, "UNIQUE ") +
strOpt(c.NullFiltered, "NULL_FILTERED ") +
"INDEX " +
strOpt(c.IfNotExists, "IF NOT EXISTS ") +
c.Name.SQL() + " ON " + c.TableName.SQL() + "(" +
sqlJoin(c.Keys, ", ") +
")" +
sqlOpt(" ", c.Storing, "") +
sqlOpt("", c.InterleaveIn, "")
}

func (c *CreateVectorIndex) SQL() string {
Expand Down
2 changes: 1 addition & 1 deletion testdata/result/ddl/create_index.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (bar DESC, baz ASC)
CREATE INDEX foo_bar ON foo(bar DESC, baz ASC)
2 changes: 1 addition & 1 deletion testdata/result/ddl/create_index_if_not_exists.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ create index if not exists foo_bar on foo (bar)
}

--- SQL
CREATE INDEX IF NOT EXISTS foo_bar ON foo (bar)
CREATE INDEX IF NOT EXISTS foo_bar ON foo(bar)
2 changes: 1 addition & 1 deletion testdata/result/ddl/create_index_interleave.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (foo DESC) STORING (bar), INTERLEAVE IN foobar
CREATE INDEX foo_bar ON foo(foo DESC) STORING (bar), INTERLEAVE IN foobar
2 changes: 1 addition & 1 deletion testdata/result/ddl/create_index_storing.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (bar ASC) STORING (foo, baz)
CREATE INDEX foo_bar ON foo(bar ASC) STORING (foo, baz)
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ create unique null_filtered index foo_bar on foo (foo)
}

--- SQL
CREATE UNIQUE NULL_FILTERED INDEX foo_bar ON foo (foo)
CREATE UNIQUE NULL_FILTERED INDEX foo_bar ON foo(foo)
2 changes: 1 addition & 1 deletion testdata/result/ddl/named_schemas_create_index.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ CREATE INDEX sch1.indexOnSingers ON sch1.Singers(FirstName)
}

--- SQL
CREATE INDEX sch1.indexOnSingers ON sch1.Singers (FirstName)
CREATE INDEX sch1.indexOnSingers ON sch1.Singers(FirstName)
2 changes: 1 addition & 1 deletion testdata/result/statement/create_index.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (bar DESC, baz ASC)
CREATE INDEX foo_bar ON foo(bar DESC, baz ASC)
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ create index if not exists foo_bar on foo (bar)
}

--- SQL
CREATE INDEX IF NOT EXISTS foo_bar ON foo (bar)
CREATE INDEX IF NOT EXISTS foo_bar ON foo(bar)
2 changes: 1 addition & 1 deletion testdata/result/statement/create_index_interleave.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (foo DESC) STORING (bar), INTERLEAVE IN foobar
CREATE INDEX foo_bar ON foo(foo DESC) STORING (bar), INTERLEAVE IN foobar
2 changes: 1 addition & 1 deletion testdata/result/statement/create_index_storing.sql.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ create index foo_bar on foo (
}

--- SQL
CREATE INDEX foo_bar ON foo (bar ASC) STORING (foo, baz)
CREATE INDEX foo_bar ON foo(bar ASC) STORING (foo, baz)
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ create unique null_filtered index foo_bar on foo (foo)
}

--- SQL
CREATE UNIQUE NULL_FILTERED INDEX foo_bar ON foo (foo)
CREATE UNIQUE NULL_FILTERED INDEX foo_bar ON foo(foo)
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ CREATE INDEX sch1.indexOnSingers ON sch1.Singers(FirstName)
}

--- SQL
CREATE INDEX sch1.indexOnSingers ON sch1.Singers (FirstName)
CREATE INDEX sch1.indexOnSingers ON sch1.Singers(FirstName)

0 comments on commit eccf53d

Please sign in to comment.