forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpgoidtype.slt
330 lines (249 loc) · 8.07 KB
/
pgoidtype.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# 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/pgoidtype
#
# 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.
mode cockroach
query OO
SELECT 3::OID, '3'::OID
----
3 3
query O
SELECT 3::OID::INT::OID
----
3
# The rest of this file is not yet supported.
halt
query OOOOOO
SELECT 1::OID, 1::REGCLASS, 1::REGNAMESPACE, 1::REGPROC, 1::REGPROCEDURE, 1::REGTYPE
----
1 1 1 1 1 1
query OOOOO
SELECT 1::OID::REGCLASS, 1::OID::REGNAMESPACE, 1::OID::REGPROC, 1::OID::REGPROCEDURE, 1::OID::REGTYPE
----
1 1 1 1 1
query TTT
SELECT pg_typeof(1::OID), pg_typeof(1::REGCLASS), pg_typeof(1::REGNAMESPACE)
----
oid regclass regnamespace
query TTT
SELECT pg_typeof(1::REGPROC), pg_typeof(1::REGPROCEDURE), pg_typeof(1::REGTYPE)
----
regproc regprocedure regtype
query TTT
SELECT pg_typeof('1'::OID), pg_typeof('pg_constraint'::REGCLASS), pg_typeof('public'::REGNAMESPACE)
----
oid regclass regnamespace
query TTT
SELECT pg_typeof('upper'::REGPROC), pg_typeof('upper'::REGPROCEDURE), pg_typeof('bool'::REGTYPE)
----
regproc regprocedure regtype
query OO
SELECT 'pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS
----
pg_constraint pg_constraint
query error pgcode 42P01 relation "foo.pg_constraint" does not exist
SELECT 'foo.pg_constraint'::REGCLASS
query OO
SELECT '"pg_constraint"'::REGCLASS, ' "pg_constraint" '::REGCLASS
----
pg_constraint pg_constraint
query OO
SELECT 'pg_constraint '::REGCLASS, ' pg_constraint '::REGCLASS
----
pg_constraint pg_constraint
query OO
SELECT 'pg_constraint '::REGCLASS, '"pg_constraint"'::REGCLASS::OID
----
pg_constraint 4294967232
query O
SELECT 4061301040::REGCLASS
----
4061301040
query OOIOT
SELECT oid, oid::regclass, oid::regclass::int, oid::regclass::int::regclass, oid::regclass::text
FROM pg_class
WHERE relname = 'pg_constraint'
----
4294967232 pg_constraint 4294967232 pg_constraint pg_constraint
query OOOO
SELECT 'upper'::REGPROC, 'upper'::REGPROCEDURE, 'pg_catalog.upper'::REGPROCEDURE, 'upper'::REGPROC::OID
----
upper upper upper 3615042040
query error invalid function name
SELECT 'invalid.more.pg_catalog.upper'::REGPROCEDURE
query OOO
SELECT 'upper(int)'::REGPROC, 'upper(int)'::REGPROCEDURE, 'upper(int)'::REGPROC::OID
----
upper upper 3615042040
query error unknown function: blah\(\)
SELECT 'blah(ignored, ignored)'::REGPROC, 'blah(ignored, ignored)'::REGPROCEDURE
query error unknown function: blah\(\)
SELECT ' blah ( ignored , ignored ) '::REGPROC
query error unknown function: blah\(\)
SELECT 'blah ()'::REGPROC
query error unknown function: blah\(\)
SELECT 'blah( )'::REGPROC
query error unknown function: blah\(, \)\(\)
SELECT 'blah(, )'::REGPROC
query error more than one function named 'sqrt'
SELECT 'sqrt'::REGPROC
query OOOO
SELECT 'array_in'::REGPROC, 'array_in(a,b,c)'::REGPROC, 'pg_catalog.array_in'::REGPROC, 'pg_catalog.array_in( a ,b, c )'::REGPROC
----
array_in array_in array_in array_in
query OOOO
SELECT 'array_in'::REGPROCEDURE, 'array_in(a,b,c)'::REGPROCEDURE, 'pg_catalog.array_in'::REGPROCEDURE, 'pg_catalog.array_in( a ,b, c )'::REGPROCEDURE
----
array_in array_in array_in array_in
query OO
SELECT 'public'::REGNAMESPACE, 'public'::REGNAMESPACE::OID
----
public 3426283741
query OO
SELECT 'bool'::REGTYPE, 'bool'::REGTYPE::OID
----
boolean 16
query OO
SELECT 'numeric(10,3)'::REGTYPE, 'numeric( 10, 3 )'::REGTYPE
----
numeric numeric
query error type 'foo.' does not exist
SELECT 'foo.'::REGTYPE
query error pgcode 42P01 relation "blah" does not exist
SELECT 'blah'::REGCLASS
query error unknown function: blah\(\)
SELECT 'blah'::REGPROC
query error unknown function: blah\(\)
SELECT 'blah'::REGPROCEDURE
query error namespace 'blah' does not exist
SELECT 'blah'::REGNAMESPACE
query error type 'blah' does not exist
SELECT 'blah'::REGTYPE
## Test other cast syntaxes
query O
SELECT CAST ('pg_constraint' AS REGCLASS)
----
pg_constraint
# This forces the b_expr form of the cast syntax.
query OO
SELECT ('pg_constraint')::REGCLASS, ('pg_constraint')::REGCLASS::OID
----
pg_constraint 4294967232
## Test visibility of pg_* via oid casts.
statement ok
CREATE TABLE a (id INT PRIMARY KEY)
query T
SELECT relname from pg_class where oid='a'::regclass
----
a
## Regression for #16767 - ensure regclass casts use normalized table names
statement ok
CREATE TABLE hasCase (id INT PRIMARY KEY)
query T
SELECT relname from pg_class where oid='hasCase'::regclass
----
hascase
statement ok
CREATE TABLE "quotedCase" (id INT PRIMARY KEY)
query error pgcode 42P01 relation "quotedcase" does not exist
SELECT relname from pg_class where oid='quotedCase'::regclass
query T
SELECT relname from pg_class where oid='"quotedCase"'::regclass
----
quotedCase
# a non-root user with sufficient permissions can get the OID of a table from
# the current database
statement ok
GRANT ALL ON DATABASE test TO testuser
statement ok
GRANT SELECT ON test.* TO testuser
user testuser
query T
SELECT relname from pg_class where oid='a'::regclass
----
a
user root
statement ok
CREATE DATABASE otherdb
## a non-root user can't get the OID of a table from a different database
user testuser
statement ok
SET DATABASE = otherdb
query error pgcode 42P01 relation "a" does not exist
SELECT 'a'::regclass
user root
statement ok
SET DATABASE = otherdb
statement ok
CREATE TABLE a (id INT PRIMARY KEY, foo STRING)
## There is now a table named 'a' in both the database 'otherdb' and the
## database 'test'. The following query shows that the root user can still
## determine the OID of the table 'a' by using a regclass cast, despite the
## fact that the root user has visibility into both of the tables. The 'a' that
## gets selected should be the 'a' that exists in the current database.
## See https://github.com/cockroachdb/cockroach/issues/13695
query OI
SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
----
a 2
statement ok
SET DATABASE = test
query OI
SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
----
a 1
statement ok
CREATE DATABASE thirddb
statement ok
SET DATABASE = thirddb
# Ensure that if the table is not in the current database, but it
# still exists in another database, the query does fail (regclass
# does not automatically search in other dbs, even for the root user).
query error pgcode 42P01 relation "a" does not exist
SELECT relname, relnatts FROM pg_class WHERE oid='a'::regclass
statement ok
CREATE TABLE o (a OID PRIMARY KEY)
statement ok
INSERT INTO o VALUES (1), (4)
query O
SELECT * FROM o WHERE a < 3
----
1
query O rowsort
SELECT * FROM o WHERE a <= 4
----
1
4
# Regression test for #23652.
query B
SELECT NOT (prorettype::regtype::text = 'foo') AND proretset FROM pg_proc WHERE proretset=false LIMIT 1
----
false
query TTTTT
SELECT crdb_internal.create_regtype(10, 'foo'), crdb_internal.create_regclass(10, 'foo'), crdb_internal.create_regproc(10, 'foo'), crdb_internal.create_regprocedure(10, 'foo'), crdb_internal.create_regnamespace(10, 'foo')
----
foo foo foo foo foo
query OOOOO
SELECT crdb_internal.create_regtype(10, 'foo')::oid, crdb_internal.create_regclass(10, 'foo')::oid, crdb_internal.create_regproc(10, 'foo')::oid, crdb_internal.create_regprocedure(10, 'foo')::oid, crdb_internal.create_regnamespace(10, 'foo')::oid
----
10 10 10 10 10
# Regression test for #32422: ensure that VALUES nodes properly retain special
# OID properties.
query OO
VALUES ('pg_constraint'::REGCLASS, 'pg_catalog.pg_constraint'::REGCLASS)
----
pg_constraint pg_constraint