Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherrypick-2.0: sql: clarify the error message upon access to vtable with no db #24809

Merged
merged 1 commit into from
Apr 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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