Исходный код СУБД 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
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
--
-- Tests for PL/pgSQL variable properties: CONSTANT, NOT NULL, initializers
--
create type var_record as (f1 int4, f2 int4);
create domain int_nn as int not null;
create domain var_record_nn as var_record not null;
create domain var_record_colnn as var_record check((value).f2 is not null);
-- CONSTANT
do $$
declare x constant int := 42;
begin
  raise notice 'x = %', x;
end$$;
NOTICE:  x = 42
do $$
declare x constant int;
begin
  x := 42;  -- fail
end$$;
ERROR:  variable "x" is declared CONSTANT
LINE 4:   x := 42;  -- fail
          ^
do $$
declare x constant int; y int;
begin
  for x, y in select 1, 2 loop  -- fail
  end loop;
end$$;
ERROR:  variable "x" is declared CONSTANT
LINE 4:   for x, y in select 1, 2 loop  -- fail
              ^
do $$
declare x constant int[];
begin
  x[1] := 42;  -- fail
end$$;
ERROR:  variable "x" is declared CONSTANT
LINE 4:   x[1] := 42;  -- fail
          ^
do $$
declare x constant int[]; y int;
begin
  for x[1], y in select 1, 2 loop  -- fail (currently, unsupported syntax)
  end loop;
end$$;
ERROR:  syntax error at or near "["
LINE 4:   for x[1], y in select 1, 2 loop  -- fail (currently, unsup...
               ^
do $$
declare x constant var_record;
begin
  x.f1 := 42;  -- fail
end$$;
ERROR:  variable "x" is declared CONSTANT
LINE 4:   x.f1 := 42;  -- fail
          ^
do $$
declare x constant var_record; y int;
begin
  for x.f1, y in select 1, 2 loop  -- fail
  end loop;
end$$;
ERROR:  variable "x" is declared CONSTANT
LINE 4:   for x.f1, y in select 1, 2 loop  -- fail
              ^
-- initializer expressions
do $$
declare x int := sin(0);
begin
  raise notice 'x = %', x;
end$$;
NOTICE:  x = 0
do $$
declare x int := 1/0;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  division by zero
CONTEXT:  PL/pgSQL expression "1/0"
PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x bigint[] := array[1,3,5];
begin
  raise notice 'x = %', x;
end$$;
NOTICE:  x = {1,3,5}
do $$
declare x record := row(1,2,3);
begin
  raise notice 'x = %', x;
end$$;
NOTICE:  x = (1,2,3)
do $$
declare x var_record := row(1,2);
begin
  raise notice 'x = %', x;
end$$;
NOTICE:  x = (1,2)
-- NOT NULL
do $$
declare x int not null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  variable "x" must have a default value, since it's declared NOT NULL
LINE 2: declare x int not null;  -- fail
                      ^
do $$
declare x int not null := 42;
begin
  raise notice 'x = %', x;
  x := null;  -- fail
end$$;
NOTICE:  x = 42
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 5 at assignment
do $$
declare x int not null := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x record not null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  variable "x" must have a default value, since it's declared NOT NULL
LINE 2: declare x record not null;  -- fail
                         ^
do $$
declare x record not null := row(42);
begin
  raise notice 'x = %', x;
  x := row(null);  -- ok
  raise notice 'x = %', x;
  x := null;  -- fail
end$$;
NOTICE:  x = (42)
NOTICE:  x = ()
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 7 at assignment
do $$
declare x record not null := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record not null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  variable "x" must have a default value, since it's declared NOT NULL
LINE 2: declare x var_record not null;  -- fail
                             ^
do $$
declare x var_record not null := row(41,42);
begin
  raise notice 'x = %', x;
  x := row(null,null);  -- ok
  raise notice 'x = %', x;
  x := null;  -- fail
end$$;
NOTICE:  x = (41,42)
NOTICE:  x = (,)
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 7 at assignment
do $$
declare x var_record not null := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  null value cannot be assigned to variable "x" declared NOT NULL
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
-- Check that variables are reinitialized on block re-entry.
do $$
begin
  for i in 1..3 loop
    declare
      x int;
      y int := i;
      r record;
      c var_record;
    begin
      if i = 1 then
        x := 42;
        r := row(i, i+1);
        c := row(i, i+1);
      end if;
      raise notice 'x = %', x;
      raise notice 'y = %', y;
      raise notice 'r = %', r;
      raise notice 'c = %', c;
    end;
  end loop;
end$$;
NOTICE:  x = 42
NOTICE:  y = 1
NOTICE:  r = (1,2)
NOTICE:  c = (1,2)
NOTICE:  x = <NULL>
NOTICE:  y = 2
NOTICE:  r = <NULL>
NOTICE:  c = <NULL>
NOTICE:  x = <NULL>
NOTICE:  y = 3
NOTICE:  r = <NULL>
NOTICE:  c = <NULL>
-- Check enforcement of domain constraints during initialization
do $$
declare x int_nn;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  domain int_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x int_nn := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  domain int_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x int_nn := 42;
begin
  raise notice 'x = %', x;
  x := null;  -- fail
end$$;
NOTICE:  x = 42
ERROR:  domain int_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 5 at assignment
do $$
declare x var_record_nn;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  domain var_record_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record_nn := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  domain var_record_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record_nn := row(1,2);
begin
  raise notice 'x = %', x;
  x := row(null,null);  -- ok
  x := null;  -- fail
end$$;
NOTICE:  x = (1,2)
ERROR:  domain var_record_nn does not allow null values
CONTEXT:  PL/pgSQL function inline_code_block line 6 at assignment
do $$
declare x var_record_colnn;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  value for domain var_record_colnn violates check constraint "var_record_colnn_check"
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record_colnn := null;  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  value for domain var_record_colnn violates check constraint "var_record_colnn_check"
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record_colnn := row(1,null);  -- fail
begin
  raise notice 'x = %', x;
end$$;
ERROR:  value for domain var_record_colnn violates check constraint "var_record_colnn_check"
CONTEXT:  PL/pgSQL function inline_code_block line 2 during statement block local variable initialization
do $$
declare x var_record_colnn := row(1,2);
begin
  raise notice 'x = %', x;
  x := null;  -- fail
end$$;
NOTICE:  x = (1,2)
ERROR:  value for domain var_record_colnn violates check constraint "var_record_colnn_check"
CONTEXT:  PL/pgSQL function inline_code_block line 5 at assignment
do $$
declare x var_record_colnn := row(1,2);
begin
  raise notice 'x = %', x;
  x := row(null,null);  -- fail
end$$;
NOTICE:  x = (1,2)
ERROR:  value for domain var_record_colnn violates check constraint "var_record_colnn_check"
CONTEXT:  PL/pgSQL function inline_code_block line 5 at assignment