Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
--
-- CREATE_SCHEMA
--
-- Schema creation with elements.
CREATE ROLE regress_create_schema_role SUPERUSER;
-- Cases where schema creation fails as objects are qualified with a schema
-- that does not match with what's expected.
-- This checks all the object types that include schema qualifications.
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE SEQUENCE schema_not_existing.seq;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE SEQUENCE schema_not_existing.seq;
                          ^
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE TABLE schema_not_existing.tab (id int);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE TABLE schema_not_existing.tab (id int);
                       ^
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE VIEW schema_not_existing.view AS SELECT 1;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE VIEW schema_not_existing.view AS SELECT 1;
                      ^
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE INDEX ON schema_not_existing.tab (id);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE INDEX ON schema_not_existing.tab (id);
                          ^
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
  EXECUTE FUNCTION schema_trig.no_func();
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_exi...
                                                      ^
-- Again, with a role specification and no schema names.
SET ROLE regress_create_schema_role;
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE SEQUENCE schema_not_existing.seq;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE SEQUENCE schema_not_existing.seq;
                          ^
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE TABLE schema_not_existing.tab (id int);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE TABLE schema_not_existing.tab (id int);
                       ^
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE VIEW schema_not_existing.view AS SELECT 1;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE VIEW schema_not_existing.view AS SELECT 1;
                      ^
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE INDEX ON schema_not_existing.tab (id);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE INDEX ON schema_not_existing.tab (id);
                          ^
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
  EXECUTE FUNCTION schema_trig.no_func();
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_create_schema_role)
LINE 2:   CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_exi...
                                                      ^
-- Again, with a schema name and a role specification.
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE SEQUENCE schema_not_existing.seq;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_schema_1)
LINE 2:   CREATE SEQUENCE schema_not_existing.seq;
                          ^
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE TABLE schema_not_existing.tab (id int);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_schema_1)
LINE 2:   CREATE TABLE schema_not_existing.tab (id int);
                       ^
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE VIEW schema_not_existing.view AS SELECT 1;
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_schema_1)
LINE 2:   CREATE VIEW schema_not_existing.view AS SELECT 1;
                      ^
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE INDEX ON schema_not_existing.tab (id);
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_schema_1)
LINE 2:   CREATE INDEX ON schema_not_existing.tab (id);
                          ^
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_existing.tab
  EXECUTE FUNCTION schema_trig.no_func();
ERROR:  CREATE specifies a schema (schema_not_existing) different from the one being created (regress_schema_1)
LINE 2:   CREATE TRIGGER schema_trig BEFORE INSERT ON schema_not_exi...
                                                      ^
RESET ROLE;
-- Cases where the schema creation succeeds.
-- The schema created matches the role name.
CREATE SCHEMA AUTHORIZATION regress_create_schema_role
  CREATE TABLE regress_create_schema_role.tab (id int);
\d regress_create_schema_role.tab
      Table "regress_create_schema_role.tab"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |           |          | 
 
DROP SCHEMA regress_create_schema_role CASCADE;
NOTICE:  drop cascades to table regress_create_schema_role.tab
-- Again, with a different role specification and no schema names.
SET ROLE regress_create_schema_role;
CREATE SCHEMA AUTHORIZATION CURRENT_ROLE
  CREATE TABLE regress_create_schema_role.tab (id int);
\d regress_create_schema_role.tab
      Table "regress_create_schema_role.tab"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |           |          | 
 
DROP SCHEMA regress_create_schema_role CASCADE;
NOTICE:  drop cascades to table tab
-- Again, with a schema name and a role specification.
CREATE SCHEMA regress_schema_1 AUTHORIZATION CURRENT_ROLE
  CREATE TABLE regress_schema_1.tab (id int);
\d regress_schema_1.tab
           Table "regress_schema_1.tab"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |           |          | 
 
DROP SCHEMA regress_schema_1 CASCADE;
NOTICE:  drop cascades to table regress_schema_1.tab
RESET ROLE;
-- Test forward-referencing foreign key clauses.
CREATE SCHEMA regress_schema_fk
    CREATE TABLE regress_schema_fk.t2 (
        b int,
        a int REFERENCES t1 DEFERRABLE INITIALLY DEFERRED NOT ENFORCED
              REFERENCES t3 DEFERRABLE INITIALLY DEFERRED,
        CONSTRAINT fk FOREIGN KEY (a) REFERENCES t1 NOT DEFERRABLE)
    CREATE TABLE regress_schema_fk.t1 (a int PRIMARY KEY)
    CREATE TABLE t3 (a int PRIMARY KEY)
    CREATE TABLE t4 (
        b int,
        a int REFERENCES t5 NOT DEFERRABLE ENFORCED
              REFERENCES t6 DEFERRABLE INITIALLY IMMEDIATE,
        CONSTRAINT fk FOREIGN KEY (a) REFERENCES t6 DEFERRABLE INITIALLY DEFERRED)
    CREATE TABLE t5 (a int, b int, PRIMARY KEY (a))
    CREATE TABLE t6 (a int, b int, PRIMARY KEY (a));
\d regress_schema_fk.t2
           Table "regress_schema_fk.t2"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 b      | integer |           |          | 
 a      | integer |           |          | 
Foreign-key constraints:
    "fk" FOREIGN KEY (a) REFERENCES regress_schema_fk.t1(a)
    "t2_a_fkey" FOREIGN KEY (a) REFERENCES regress_schema_fk.t1(a) DEFERRABLE INITIALLY DEFERRED NOT ENFORCED
    "t2_a_fkey1" FOREIGN KEY (a) REFERENCES regress_schema_fk.t3(a) DEFERRABLE INITIALLY DEFERRED
 
\d regress_schema_fk.t4
           Table "regress_schema_fk.t4"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 b      | integer |           |          | 
 a      | integer |           |          | 
Foreign-key constraints:
    "fk" FOREIGN KEY (a) REFERENCES regress_schema_fk.t6(a) DEFERRABLE INITIALLY DEFERRED
    "t4_a_fkey" FOREIGN KEY (a) REFERENCES regress_schema_fk.t5(a)
    "t4_a_fkey1" FOREIGN KEY (a) REFERENCES regress_schema_fk.t6(a) DEFERRABLE
 
DROP SCHEMA regress_schema_fk CASCADE;
NOTICE:  drop cascades to 6 other objects
DETAIL:  drop cascades to table regress_schema_fk.t2
drop cascades to table regress_schema_fk.t1
drop cascades to table regress_schema_fk.t3
drop cascades to table regress_schema_fk.t4
drop cascades to table regress_schema_fk.t5
drop cascades to table regress_schema_fk.t6
-- Clean up
DROP ROLE regress_create_schema_role;