Skip to content

Commit

Permalink
release-19.2: sqlbase: link to issue #42508 in sequence-relate… (#42530)
Browse files Browse the repository at this point in the history
release-19.2: sqlbase: link to issue #42508 in sequence-related errors
  • Loading branch information
knz authored Nov 18, 2019
2 parents 53eef08 + a234188 commit b4bc5be
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
27 changes: 26 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/schema_change_in_txn
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pkg/sql/sqlbase/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/sqlbase/evalctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit b4bc5be

Please sign in to comment.