Skip to content

Commit

Permalink
Merge #24809
Browse files Browse the repository at this point in the history
24809: cherrypick-2.0: sql: clarify the error message upon access to vtable with no db r=knz a=knz

Picks #24772.

cc @cockroachdb/release 

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed Apr 17, 2018
2 parents 06c16a3 + 0e69155 commit ff9c5a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/namespace
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SELECT x FROM pg_type

# Leave database, check name resolves to default.
# The expected error can only occur on the virtual pg_type, not the physical one.
query error no database specified
query error cannot access virtual schema in anonymous database
SET database = ''; SELECT * FROM pg_type

# Go to different database, check name still resolves to default.
Expand Down
14 changes: 7 additions & 7 deletions pkg/sql/logictest/testdata/logic_test/pg_catalog
Original file line number Diff line number Diff line change
Expand Up @@ -1321,29 +1321,29 @@ user root
statement ok
SET DATABASE = ''

query error no database specified
query error cannot access virtual schema in anonymous database
SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='public' ORDER BY 1

query error no database specified
query error cannot access virtual schema in anonymous database
SELECT viewname FROM pg_catalog.pg_views WHERE schemaname='public' ORDER BY 1

query error no database specified
query error cannot access virtual schema in anonymous database
SELECT relname FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
WHERE nspname='public'

query error no database specified
query error cannot access virtual schema in anonymous database
SELECT conname FROM pg_catalog.pg_constraint con
JOIN pg_catalog.pg_namespace n ON con.connamespace = n.oid
WHERE n.nspname = 'public'

query error no database specified
query error cannot access virtual schema in anonymous database
SELECT COUNT(*) FROM pg_catalog.pg_depend

query error no database specified
query error cannot access virtual schema in anonymous database
select 'upper'::REGPROC;

query error no database specified
query error cannot access virtual schema in anonymous database
select 'system.namespace'::regclass

statement ok
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/virtual_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/sql/parser"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
)
Expand Down Expand Up @@ -93,6 +94,10 @@ type virtualTableEntry struct {

type virtualTableConstructor func(context.Context, *planner, string) (planNode, error)

var errInvalidDbPrefix = pgerror.NewError(pgerror.CodeUndefinedObjectError,
"cannot access virtual schema in anonymous database",
).SetHintf("verify that the current database is set")

// getPlanInfo returns the column metadata and a constructor for a new
// valuesNode for the virtual table. We use deferred construction here
// so as to avoid populating a RowContainer during query preparation,
Expand All @@ -119,7 +124,7 @@ func (e virtualTableEntry) getPlanInfo(
}
} else {
if !e.validWithNoDatabaseContext {
return nil, errNoDatabase
return nil, errInvalidDbPrefix
}
}

Expand Down

0 comments on commit ff9c5a0

Please sign in to comment.