forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnamespace.slt
134 lines (107 loc) · 3.54 KB
/
namespace.slt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# This file is derived from the logic test suite in CockroachDB. The
# original file was retrieved on June 10, 2019 from:
#
# https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/namespace
#
# The original source code is subject to the terms of the Apache
# 2.0 license, a copy of which can be found in the LICENSE file at the
# root of this repository.
# not supported yet
halt
mode cockroach
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 cannot access virtual schema in anonymous database
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
statement ok
DROP TABLE pg_type; RESET search_path; SET database = test
# Unqualified index name resolution.
statement ok
ALTER INDEX "primary" RENAME TO a_pk
# Schema-qualified index name resolution.
statement ok
ALTER INDEX public.a_pk RENAME TO a_pk2
# DB-qualified index name resolution (CRDB 1.x compat).
statement ok
ALTER INDEX test.a_pk2 RENAME TO a_pk3
statement ok
CREATE DATABASE public; CREATE TABLE public.public.t(a INT)
# We can't see the DB "public" with DB-qualified index name resolution.
statement error index "primary" does not exist
ALTER INDEX public."primary" RENAME TO t_pk
# But we can see it with sufficient qualification.
statement ok
ALTER INDEX public.public."primary" RENAME TO t_pk
# If the search path is invalid, we get a special error.
statement ok
SET search_path = invalid
statement error schema or database was not found while searching index: "a_pk3"
ALTER INDEX a_pk3 RENAME TO a_pk4
# But qualification resolves the problem.
statement ok
ALTER INDEX public.a_pk3 RENAME TO a_pk4