Skip to content

Commit

Permalink
sem/tree: fix the formatting of backup options
Browse files Browse the repository at this point in the history
Found using TestRandomSyntax.

Release note: None
  • Loading branch information
knz committed Jan 13, 2023
1 parent 6f5d89e commit ba5ac5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/parser/testdata/backup_restore
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,16 @@ BACKUP TABLE (foo) TO ('bar') WITH revision_history = (true), detached, kms = ((
BACKUP TABLE foo TO '_' WITH revision_history = _, detached, kms = ('_', '_') -- literals removed
BACKUP TABLE _ TO 'bar' WITH revision_history = true, detached, kms = ('foo', 'bar') -- identifiers removed


# Regression test for #95235.
parse
BACKUP foo TO 'bar' WITH OPTIONS (detached = false)
----
BACKUP TABLE foo TO 'bar' WITH detached = FALSE -- normalized!
BACKUP TABLE (foo) TO ('bar') WITH detached = FALSE -- fully parenthesized
BACKUP TABLE foo TO '_' WITH detached = FALSE -- literals removed
BACKUP TABLE _ TO 'bar' WITH detached = FALSE -- identifiers removed

parse
BACKUP TENANT 36 TO 'bar'
----
Expand Down
8 changes: 6 additions & 2 deletions pkg/sql/sem/tree/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,12 @@ func (o *BackupOptions) Format(ctx *FmtCtx) {
}
}

if o.Detached == DBoolTrue {
if o.Detached != nil {
maybeAddSep()
ctx.WriteString("detached")
if o.Detached != DBoolTrue {
ctx.WriteString(" = FALSE")
}
}

if o.EncryptionKMSURI != nil {
Expand Down Expand Up @@ -334,7 +337,8 @@ func (o *BackupOptions) CombineWith(other *BackupOptions) error {
func (o BackupOptions) IsDefault() bool {
options := BackupOptions{}
return o.CaptureRevisionHistory == options.CaptureRevisionHistory &&
o.Detached == options.Detached && cmp.Equal(o.EncryptionKMSURI, options.EncryptionKMSURI) &&
o.Detached == options.Detached &&
cmp.Equal(o.EncryptionKMSURI, options.EncryptionKMSURI) &&
o.EncryptionPassphrase == options.EncryptionPassphrase &&
cmp.Equal(o.IncrementalStorage, options.IncrementalStorage)
}
Expand Down

0 comments on commit ba5ac5b

Please sign in to comment.