diff --git a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn index 048458b55c76..dcfb766957f7 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn +++ b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn @@ -520,7 +520,7 @@ CREATE TABLE shopping (item, quantity) AS VALUES ('cups', 10), ('plates', 30), ( statement count 3 SELECT * FROM shopping -statement error pgcode 42P15 division by zero +statement error pgcode 22012 division by zero ALTER TABLE shopping ADD COLUMN c int AS (quantity::int // 0) STORED statement ok @@ -1746,3 +1746,28 @@ DROP TABLE people; statement ok COMMIT; + +subtest add_column_default_sequence_op + +# This is a current known limitation (#42508). This test ensures that +# the error message is properly reported, with issue hint. +# Once the limitation is lifted, this entire test can be removed +# (and replaced by test for the feature). + +statement ok +CREATE TABLE t42508(x INT); INSERT INTO t42508(x) VALUES (1); + +statement ok +CREATE SEQUENCE s42508 + +statement error pgcode 0A000 unimplemented: cannot backfill such sequence operation.*\nHINT.*\n.*42508 +ALTER TABLE t42508 ADD COLUMN y INT DEFAULT nextval('s42508') + +statement ok +BEGIN + +statement ok +ALTER TABLE t42508 ADD COLUMN y INT DEFAULT nextval('s42508') + +statement error pgcode XXA00 unimplemented: cannot backfill such sequence operation.*\nHINT.*\n.*42508 +COMMIT diff --git a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn-mixed-19.1-19.2 b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn-mixed-19.1-19.2 index d9b78f36bcd1..da68e12382ba 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn-mixed-19.1-19.2 +++ b/pkg/sql/logictest/testdata/logic_test/schema_change_in_txn-mixed-19.1-19.2 @@ -495,7 +495,7 @@ CREATE TABLE shopping (item, quantity) AS VALUES ('cups', 10), ('plates', 30), ( statement count 3 SELECT * FROM shopping -statement error pgcode 42P15 division by zero +statement error pgcode 22012 division by zero ALTER TABLE shopping ADD COLUMN c int AS (quantity::int // 0) STORED statement ok @@ -1340,3 +1340,28 @@ COMMIT statement ok DROP TABLE t + +subtest add_column_default_sequence_op + +# This is a current known limitation (#42508). This test ensures that +# the error message is properly reported, with issue hint. +# Once the limitation is lifted, this entire test can be removed +# (and replaced by test for the feature). + +statement ok +CREATE TABLE t42508(x INT); INSERT INTO t42508(x) VALUES (1); + +statement ok +CREATE SEQUENCE s42508 + +statement error pgcode 0A000 unimplemented: cannot backfill such sequence operation.*\nHINT.*\n.*42508 +ALTER TABLE t42508 ADD COLUMN y INT DEFAULT nextval('s42508') + +statement ok +BEGIN + +statement ok +ALTER TABLE t42508 ADD COLUMN y INT DEFAULT nextval('s42508') + +statement error pgcode XXA00 unimplemented: cannot backfill such sequence operation.*\nHINT.*\n.*42508 +COMMIT diff --git a/pkg/sql/sqlbase/errors.go b/pkg/sql/sqlbase/errors.go index 4ccbdd26009c..7829ee22c351 100644 --- a/pkg/sql/sqlbase/errors.go +++ b/pkg/sql/sqlbase/errors.go @@ -49,7 +49,7 @@ func NewNonNullViolationError(columnName string) error { // NewInvalidSchemaDefinitionError creates an error for an invalid schema // definition such as a schema definition that doesn't parse. func NewInvalidSchemaDefinitionError(err error) error { - return pgerror.New(pgcode.InvalidSchemaDefinition, err.Error()) + return pgerror.WithCandidateCode(err, pgcode.InvalidSchemaDefinition) } // NewUnsupportedSchemaUsageError creates an error for an invalid diff --git a/pkg/sql/sqlbase/evalctx.go b/pkg/sql/sqlbase/evalctx.go index d892aae215db..6ac61297e5dc 100644 --- a/pkg/sql/sqlbase/evalctx.go +++ b/pkg/sql/sqlbase/evalctx.go @@ -15,7 +15,8 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" - "github.com/pkg/errors" + "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" + "github.com/cockroachdb/errors" ) // DummySequenceOperators implements the tree.SequenceOperators interface by @@ -24,7 +25,7 @@ type DummySequenceOperators struct{} var _ tree.EvalDatabase = &DummySequenceOperators{} -var errSequenceOperators = errors.New("cannot backfill such sequence operation") +var errSequenceOperators = unimplemented.NewWithIssue(42508, "cannot backfill such sequence operation") // ParseQualifiedTableName is part of the tree.EvalDatabase interface. func (so *DummySequenceOperators) ParseQualifiedTableName(