# LogicTest: default distsql

statement ok
CREATE TABLE a(a INT)

statement ok
CREATE DATABASE public; CREATE TABLE public.public.t(a INT)

# "public" with the current database designates the public schema
query T
SHOW TABLES FROM public
----
a

# To access all tables in database "public", one must specify
# its public schema explicitly.
query T
SHOW TABLES FROM public.public
----
t

# Of course one can also list the tables in "public" by making it the
# current database.
statement ok
SET DATABASE = public

query T
SHOW TABLES
----
t

statement ok
SET DATABASE = test; DROP DATABASE public

# Unqualified pg_type resolves from pg_catalog.
query T
SELECT typname FROM pg_type WHERE typname = 'date'
----
date

# Override table and check name resolves properly.
statement ok
SET SEARCH_PATH=public,pg_catalog

statement ok
CREATE TABLE pg_type(x INT); INSERT INTO pg_type VALUES(42)

query I
SELECT x FROM pg_type
----
42

# 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
SET DATABASE = ''; SELECT * FROM pg_type

# Go to different database, check name still resolves to default.
query T
CREATE DATABASE foo; SET DATABASE = foo; SELECT typname FROM pg_type WHERE typname = 'date'
----
date

# Verify that pg_catalog at the beginning of the search path takes precedence.
query T
SET DATABASE = test; SET SEARCH_PATH = pg_catalog,public; SELECT typname FROM pg_type WHERE typname = 'date'
----
date

# Now set the search path to the testdb, placing pg_catalog explicitly
# at the end.
query I
SET SEARCH_PATH = public,pg_catalog; SELECT x FROM pg_type
----
42
