-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql/schemachanger: support ADD COLUMN SERIAL for DSC unique_rowid only
Previously we could only add SERIAL columns with the legacy schema changer with these code changes the ALTER TABLE ADD COLUMN statement can now add SERIAL type columns via the declarative schema changer for the default rowid serial_normalization mode. Informs: #126900 Release note: none
- Loading branch information
1 parent
df4c2cd
commit e023883
Showing
21 changed files
with
1,820 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2024 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package catalog | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" | ||
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
) | ||
|
||
func UseRowID(d tree.ColumnTableDef) *tree.ColumnTableDef { | ||
d.DefaultExpr.Expr = &tree.FuncExpr{Func: tree.WrapFunction("unique_rowid")} | ||
d.Type = types.Int | ||
// Column is non-nullable in all cases. PostgreSQL requires this. | ||
d.Nullable.Nullability = tree.NotNull | ||
|
||
return &d | ||
} | ||
|
||
func AssertValidSerialColumnDef(d *tree.ColumnTableDef, tableName *tree.TableName) error { | ||
if d.HasDefaultExpr() { | ||
// SERIAL implies a new default expression, we can't have one to | ||
// start with. This is the error produced by pg in such case. | ||
return pgerror.Newf(pgcode.Syntax, | ||
"multiple default values specified for column %q of table %q", | ||
tree.ErrString(&d.Name), tree.ErrString(tableName)) | ||
} | ||
|
||
if d.Nullable.Nullability == tree.Null { | ||
// SERIAL implies a non-NULL column, we can't accept a nullability | ||
// spec. This is the error produced by pg in such case. | ||
return pgerror.Newf(pgcode.Syntax, | ||
"conflicting NULL/NOT NULL declarations for column %q of table %q", | ||
tree.ErrString(&d.Name), tree.ErrString(tableName)) | ||
} | ||
|
||
if d.Computed.Expr != nil { | ||
// SERIAL cannot be a computed column. | ||
return pgerror.Newf(pgcode.Syntax, | ||
"SERIAL column %q of table %q cannot be computed", | ||
tree.ErrString(&d.Name), tree.ErrString(tableName)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.