]> granicus.if.org Git - postgresql/blob - src/pl/tcl/expected/pltcl_queries.out
PL/Tcl: Improve trigger tests organization
[postgresql] / src / pl / tcl / expected / pltcl_queries.out
1 -- suppress CONTEXT so that function OIDs aren't in output
2 \set VERBOSITY terse
3 -- Test composite-type arguments
4 select tcl_composite_arg_ref1(row('tkey', 42, 'ref2'));
5  tcl_composite_arg_ref1 
6 ------------------------
7                      42
8 (1 row)
9
10 select tcl_composite_arg_ref2(row('tkey', 42, 'ref2'));
11  tcl_composite_arg_ref2 
12 ------------------------
13  ref2                
14 (1 row)
15
16 -- More tests for composite argument/result types
17 create domain d_comp1 as T_comp1 check ((value).ref1 > 0);
18 create function tcl_record_arg(record, fldname text) returns int as '
19     return $1($2)
20 ' language pltcl;
21 select tcl_record_arg(row('tkey', 42, 'ref2')::T_comp1, 'ref1');
22  tcl_record_arg 
23 ----------------
24              42
25 (1 row)
26
27 select tcl_record_arg(row('tkey', 42, 'ref2')::d_comp1, 'ref1');
28  tcl_record_arg 
29 ----------------
30              42
31 (1 row)
32
33 select tcl_record_arg(row(2,4), 'f2');
34  tcl_record_arg 
35 ----------------
36               4
37 (1 row)
38
39 create function tcl_cdomain_arg(d_comp1) returns int as '
40     return $1(ref1)
41 ' language pltcl;
42 select tcl_cdomain_arg(row('tkey', 42, 'ref2'));
43  tcl_cdomain_arg 
44 -----------------
45               42
46 (1 row)
47
48 select tcl_cdomain_arg(row('tkey', 42, 'ref2')::T_comp1);
49  tcl_cdomain_arg 
50 -----------------
51               42
52 (1 row)
53
54 select tcl_cdomain_arg(row('tkey', -1, 'ref2'));  -- fail
55 ERROR:  value for domain d_comp1 violates check constraint "d_comp1_check"
56 -- Test argisnull primitive
57 select tcl_argisnull('foo');
58  tcl_argisnull 
59 ---------------
60  f
61 (1 row)
62
63 select tcl_argisnull('');
64  tcl_argisnull 
65 ---------------
66  f
67 (1 row)
68
69 select tcl_argisnull(null);
70  tcl_argisnull 
71 ---------------
72  t
73 (1 row)
74
75 -- test some error cases
76 create function tcl_error(out a int, out b int) as $$return {$$ language pltcl;
77 select tcl_error();
78 ERROR:  missing close-brace
79 create function bad_record(out a text, out b text) as $$return [list a]$$ language pltcl;
80 select bad_record();
81 ERROR:  column name/value list must have even number of elements
82 create function bad_field(out a text, out b text) as $$return [list a 1 b 2 cow 3]$$ language pltcl;
83 select bad_field();
84 ERROR:  column name/value list contains nonexistent column name "cow"
85 -- test compound return
86 select * from tcl_test_cube_squared(5);
87  squared | cubed 
88 ---------+-------
89       25 |   125
90 (1 row)
91
92 -- test SRF
93 select * from tcl_test_squared_rows(0,5);
94  x | y  
95 ---+----
96  0 |  0
97  1 |  1
98  2 |  4
99  3 |  9
100  4 | 16
101 (5 rows)
102
103 select * from tcl_test_sequence(0,5) as a;
104  a 
105 ---
106  0
107  1
108  2
109  3
110  4
111 (5 rows)
112
113 select 1, tcl_test_sequence(0,5);
114  ?column? | tcl_test_sequence 
115 ----------+-------------------
116         1 |                 0
117         1 |                 1
118         1 |                 2
119         1 |                 3
120         1 |                 4
121 (5 rows)
122
123 create function non_srf() returns int as $$return_next 1$$ language pltcl;
124 select non_srf();
125 ERROR:  return_next cannot be used in non-set-returning functions
126 create function bad_record_srf(out a text, out b text) returns setof record as $$
127 return_next [list a]
128 $$ language pltcl;
129 select bad_record_srf();
130 ERROR:  column name/value list must have even number of elements
131 create function bad_field_srf(out a text, out b text) returns setof record as $$
132 return_next [list a 1 b 2 cow 3]
133 $$ language pltcl;
134 select bad_field_srf();
135 ERROR:  column name/value list contains nonexistent column name "cow"
136 -- test composite and domain-over-composite results
137 create function tcl_composite_result(int) returns T_comp1 as $$
138 return [list tkey tkey1 ref1 $1 ref2 ref22]
139 $$ language pltcl;
140 select tcl_composite_result(1001);
141             tcl_composite_result            
142 --------------------------------------------
143  ("tkey1     ",1001,"ref22               ")
144 (1 row)
145
146 select * from tcl_composite_result(1002);
147     tkey    | ref1 |         ref2         
148 ------------+------+----------------------
149  tkey1      | 1002 | ref22               
150 (1 row)
151
152 create function tcl_dcomposite_result(int) returns d_comp1 as $$
153 return [list tkey tkey2 ref1 $1 ref2 ref42]
154 $$ language pltcl;
155 select tcl_dcomposite_result(1001);
156            tcl_dcomposite_result            
157 --------------------------------------------
158  ("tkey2     ",1001,"ref42               ")
159 (1 row)
160
161 select * from tcl_dcomposite_result(1002);
162     tkey    | ref1 |         ref2         
163 ------------+------+----------------------
164  tkey2      | 1002 | ref42               
165 (1 row)
166
167 select * from tcl_dcomposite_result(-1);  -- fail
168 ERROR:  value for domain d_comp1 violates check constraint "d_comp1_check"
169 create function tcl_record_result(int) returns record as $$
170 return [list q1 sometext q2 $1 q3 moretext]
171 $$ language pltcl;
172 select tcl_record_result(42);  -- fail
173 ERROR:  function returning record called in context that cannot accept type record
174 select * from tcl_record_result(42);  -- fail
175 ERROR:  a column definition list is required for functions returning "record" at character 15
176 select * from tcl_record_result(42) as (q1 text, q2 int, q3 text);
177     q1    | q2 |    q3    
178 ----------+----+----------
179  sometext | 42 | moretext
180 (1 row)
181
182 select * from tcl_record_result(42) as (q1 text, q2 int, q3 text, q4 int);
183     q1    | q2 |    q3    | q4 
184 ----------+----+----------+----
185  sometext | 42 | moretext |   
186 (1 row)
187
188 select * from tcl_record_result(42) as (q1 text, q2 int, q4 int);  -- fail
189 ERROR:  column name/value list contains nonexistent column name "q3"
190 -- test quote
191 select tcl_eval('quote foo bar');
192 ERROR:  wrong # args: should be "quote string"
193 select tcl_eval('quote [format %c 39]');
194  tcl_eval 
195 ----------
196  ''
197 (1 row)
198
199 select tcl_eval('quote [format %c 92]');
200  tcl_eval 
201 ----------
202  \\
203 (1 row)
204
205 -- Test argisnull
206 select tcl_eval('argisnull');
207 ERROR:  wrong # args: should be "argisnull argno"
208 select tcl_eval('argisnull 14');
209 ERROR:  argno out of range
210 select tcl_eval('argisnull abc');
211 ERROR:  expected integer but got "abc"
212 -- Test return_null
213 select tcl_eval('return_null 14');
214 ERROR:  wrong # args: should be "return_null "
215 -- Test spi_exec
216 select tcl_eval('spi_exec');
217 ERROR:  wrong # args: should be "spi_exec ?-count n? ?-array name? query ?loop body?"
218 select tcl_eval('spi_exec -count');
219 ERROR:  missing argument to -count or -array
220 select tcl_eval('spi_exec -array');
221 ERROR:  missing argument to -count or -array
222 select tcl_eval('spi_exec -count abc');
223 ERROR:  expected integer but got "abc"
224 select tcl_eval('spi_exec query loop body toomuch');
225 ERROR:  wrong # args: should be "query ?loop body?"
226 select tcl_eval('spi_exec "begin; rollback;"');
227 ERROR:  pltcl: SPI_execute failed: SPI_ERROR_TRANSACTION
228 -- Test spi_execp
229 select tcl_eval('spi_execp');
230 ERROR:  missing argument to -count or -array
231 select tcl_eval('spi_execp -count');
232 ERROR:  missing argument to -array, -count or -nulls
233 select tcl_eval('spi_execp -array');
234 ERROR:  missing argument to -array, -count or -nulls
235 select tcl_eval('spi_execp -count abc');
236 ERROR:  expected integer but got "abc"
237 select tcl_eval('spi_execp -nulls');
238 ERROR:  missing argument to -array, -count or -nulls
239 select tcl_eval('spi_execp ""');
240 ERROR:  invalid queryid ''
241 -- test spi_prepare
242 select tcl_eval('spi_prepare');
243 ERROR:  wrong # args: should be "spi_prepare query argtypes"
244 select tcl_eval('spi_prepare a b');
245 ERROR:  type "b" does not exist
246 select tcl_eval('spi_prepare a "b {"');
247 ERROR:  unmatched open brace in list
248 select tcl_error_handling_test($tcl$spi_prepare "select moo" []$tcl$);
249        tcl_error_handling_test        
250 --------------------------------------
251  SQLSTATE: 42703                     +
252  condition: undefined_column         +
253  cursor_position: 8                  +
254  message: column "moo" does not exist+
255  statement: select moo
256 (1 row)
257
258 -- test full error text
259 select tcl_error_handling_test($tcl$
260 spi_exec "DO $$
261 BEGIN
262 RAISE 'my message'
263         USING HINT = 'my hint'
264         , DETAIL = 'my detail'
265         , SCHEMA = 'my schema'
266         , TABLE = 'my table'
267         , COLUMN = 'my column'
268         , CONSTRAINT = 'my constraint'
269         , DATATYPE = 'my datatype'
270 ;
271 END$$;"
272 $tcl$);
273                    tcl_error_handling_test                    
274 --------------------------------------------------------------
275  SQLSTATE: P0001                                             +
276  column: my column                                           +
277  condition: raise_exception                                  +
278  constraint: my constraint                                   +
279  context: PL/pgSQL function inline_code_block line 3 at RAISE+
280          SQL statement "DO $$                                +
281          BEGIN                                               +
282          RAISE 'my message'                                  +
283                  USING HINT = 'my hint'                      +
284                  , DETAIL = 'my detail'                      +
285                  , SCHEMA = 'my schema'                      +
286                  , TABLE = 'my table'                        +
287                  , COLUMN = 'my column'                      +
288                  , CONSTRAINT = 'my constraint'              +
289                  , DATATYPE = 'my datatype'                  +
290          ;                                                   +
291          END$$;"                                             +
292  datatype: my datatype                                       +
293  detail: my detail                                           +
294  hint: my hint                                               +
295  message: my message                                         +
296  schema: my schema                                           +
297  table: my table
298 (1 row)
299
300 -- verify tcl_error_handling_test() properly reports non-postgres errors
301 select tcl_error_handling_test('moo');
302   tcl_error_handling_test   
303 ----------------------------
304  invalid command name "moo"
305 (1 row)
306
307 -- test elog
308 select tcl_eval('elog');
309 ERROR:  wrong # args: should be "elog level msg"
310 select tcl_eval('elog foo bar');
311 ERROR:  bad priority "foo": must be DEBUG, LOG, INFO, NOTICE, WARNING, ERROR, or FATAL
312 -- test forced error
313 select tcl_eval('error "forced error"');
314 ERROR:  forced error
315 -- test loop control in spi_exec[p]
316 select tcl_spi_exec(true, 'break');
317 NOTICE:  col1 1, col2 foo
318 NOTICE:  col1 2, col2 bar
319 NOTICE:  action: break
320 NOTICE:  end of function
321  tcl_spi_exec 
322 --------------
323  
324 (1 row)
325
326 select tcl_spi_exec(true, 'continue');
327 NOTICE:  col1 1, col2 foo
328 NOTICE:  col1 2, col2 bar
329 NOTICE:  action: continue
330 NOTICE:  col1 3, col2 baz
331 NOTICE:  end of function
332  tcl_spi_exec 
333 --------------
334  
335 (1 row)
336
337 select tcl_spi_exec(true, 'error');
338 NOTICE:  col1 1, col2 foo
339 NOTICE:  col1 2, col2 bar
340 NOTICE:  action: error
341 ERROR:  error message
342 select tcl_spi_exec(true, 'return');
343 NOTICE:  col1 1, col2 foo
344 NOTICE:  col1 2, col2 bar
345 NOTICE:  action: return
346  tcl_spi_exec 
347 --------------
348  
349 (1 row)
350
351 select tcl_spi_exec(false, 'break');
352 NOTICE:  col1 1, col2 foo
353 NOTICE:  col1 2, col2 bar
354 NOTICE:  action: break
355 NOTICE:  end of function
356  tcl_spi_exec 
357 --------------
358  
359 (1 row)
360
361 select tcl_spi_exec(false, 'continue');
362 NOTICE:  col1 1, col2 foo
363 NOTICE:  col1 2, col2 bar
364 NOTICE:  action: continue
365 NOTICE:  col1 3, col2 baz
366 NOTICE:  end of function
367  tcl_spi_exec 
368 --------------
369  
370 (1 row)
371
372 select tcl_spi_exec(false, 'error');
373 NOTICE:  col1 1, col2 foo
374 NOTICE:  col1 2, col2 bar
375 NOTICE:  action: error
376 ERROR:  error message
377 select tcl_spi_exec(false, 'return');
378 NOTICE:  col1 1, col2 foo
379 NOTICE:  col1 2, col2 bar
380 NOTICE:  action: return
381  tcl_spi_exec 
382 --------------
383  
384 (1 row)
385
386 -- forcibly run the Tcl event loop for awhile, to check that we have not
387 -- messed things up too badly by disabling the Tcl notifier subsystem
388 select tcl_eval($$
389   unset -nocomplain ::tcl_vwait
390   after 100 {set ::tcl_vwait 1}
391   vwait ::tcl_vwait
392   unset -nocomplain ::tcl_vwait$$);
393  tcl_eval 
394 ----------
395  
396 (1 row)
397