Skip to content

Commit

Permalink
fix(spanner/spansql): fix SQL for CREATE CHANGE STREAM TableName; case (
Browse files Browse the repository at this point in the history
#7514)

Co-authored-by: rahul2393 <irahul@google.com>
  • Loading branch information
nktks and rahul2393 committed Mar 7, 2023
1 parent 7eadfa3 commit fc5fd86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions spanner/spansql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ func (cr CreateRole) SQL() string {

func (cs CreateChangeStream) SQL() string {
str := "CREATE CHANGE STREAM "
str += cs.Name.SQL() + " FOR "
str += cs.Name.SQL()
if cs.WatchAllTables {
str += "ALL"
str += " FOR ALL"
} else {
for i, table := range cs.Watch {
if i > 0 {
if i == 0 {
str += " FOR "
} else {
str += ", "
}
str += table.SQL()
Expand Down
8 changes: 8 additions & 0 deletions spanner/spansql/sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,14 @@ func TestSQL(t *testing.T) {
"ALTER DATABASE dbname SET OPTIONS (optimizer_version=null, optimizer_statistics_package=null, version_retention_period=null, enable_key_visualizer=null, default_leader=null)",
reparseDDL,
},
{
&CreateChangeStream{
Name: "csname",
Position: line(1),
},
"CREATE CHANGE STREAM csname",
reparseDDL,
},
{
&CreateChangeStream{
Name: "csname",
Expand Down

0 comments on commit fc5fd86

Please sign in to comment.