| 1 |
-- Test composite-type arguments |
| 2 |
select tcl_composite_arg_ref1(row('tkey', 42, 'ref2')); |
| 3 |
tcl_composite_arg_ref1 |
| 4 |
------------------------ |
| 5 |
42 |
| 6 |
(1 row) |
| 7 |
|
| 8 |
select tcl_composite_arg_ref2(row('tkey', 42, 'ref2')); |
| 9 |
tcl_composite_arg_ref2 |
| 10 |
------------------------ |
| 11 |
ref2 |
| 12 |
(1 row) |
| 13 |
|
| 14 |
-- More tests for composite argument/result types |
| 15 |
create domain d_comp1 as T_comp1 check ((value).ref1 > 0); |
| 16 |
create function tcl_record_arg(record, fldname text) returns int as ' |
| 17 |
return $1($2) |
| 18 |
' language pltcl; |
| 19 |
select tcl_record_arg(row('tkey', 42, 'ref2')::T_comp1, 'ref1'); |
| 20 |
tcl_record_arg |
| 21 |
---------------- |
| 22 |
42 |
| 23 |
(1 row) |
| 24 |
|
| 25 |
select tcl_record_arg(row('tkey', 42, 'ref2')::d_comp1, 'ref1'); |
| 26 |
tcl_record_arg |
| 27 |
---------------- |
| 28 |
42 |
| 29 |
(1 row) |
| 30 |
|
| 31 |
select tcl_record_arg(row(2,4), 'f2'); |
| 32 |
tcl_record_arg |
| 33 |
---------------- |
| 34 |
4 |
| 35 |
(1 row) |
| 36 |
|
| 37 |
create function tcl_cdomain_arg(d_comp1) returns int as ' |
| 38 |
return $1(ref1) |
| 39 |
' language pltcl; |
| 40 |
select tcl_cdomain_arg(row('tkey', 42, 'ref2')); |
| 41 |
tcl_cdomain_arg |
| 42 |
----------------- |
| 43 |
42 |
| 44 |
(1 row) |
| 45 |
|
| 46 |
select tcl_cdomain_arg(row('tkey', 42, 'ref2')::T_comp1); |
| 47 |
tcl_cdomain_arg |
| 48 |
----------------- |
| 49 |
42 |
| 50 |
(1 row) |
| 51 |
|
| 52 |
select tcl_cdomain_arg(row('tkey', -1, 'ref2')); -- fail |
| 53 |
ERROR: value for domain d_comp1 violates check constraint "d_comp1_check" |
| 54 |
-- Test argisnull primitive |
| 55 |
select tcl_argisnull('foo'); |
| 56 |
tcl_argisnull |
| 57 |
--------------- |
| 58 |
f |
| 59 |
(1 row) |
| 60 |
|
| 61 |
select tcl_argisnull(''); |
| 62 |
tcl_argisnull |
| 63 |
--------------- |
| 64 |
f |
| 65 |
(1 row) |
| 66 |
|
| 67 |
select tcl_argisnull(null); |
| 68 |
tcl_argisnull |
| 69 |
--------------- |
| 70 |
t |
| 71 |
(1 row) |
| 72 |
|
| 73 |
-- test some error cases |
| 74 |
create function tcl_error(out a int, out b int) as $$returm 1$$ language pltcl; |
| 75 |
select tcl_error(); |
| 76 |
ERROR: invalid command name "returm" |
| 77 |
CONTEXT: while executing |
| 78 |
"returm 1" |
| 79 |
(procedure "__PLTcl_proc_tcl_error" line 2) |
| 80 |
invoked from within |
| 81 |
"__PLTcl_proc_tcl_error" |
| 82 |
in PL/Tcl function tcl_error() |
| 83 |
create function bad_record(out a text, out b text) as $$return [list a]$$ language pltcl; |
| 84 |
select bad_record(); |
| 85 |
ERROR: column name/value list must have even number of elements |
| 86 |
create function bad_field(out a text, out b text) as $$return [list a 1 b 2 cow 3]$$ language pltcl; |
| 87 |
select bad_field(); |
| 88 |
ERROR: column name/value list contains nonexistent column name "cow" |
| 89 |
-- test compound return |
| 90 |
select * from tcl_test_cube_squared(5); |
| 91 |
squared | cubed |
| 92 |
---------+------- |
| 93 |
25 | 125 |
| 94 |
(1 row) |
| 95 |
|
| 96 |
-- test SRF |
| 97 |
select * from tcl_test_squared_rows(0,5); |
| 98 |
x | y |
| 99 |
---+---- |
| 100 |
0 | 0 |
| 101 |
1 | 1 |
| 102 |
2 | 4 |
| 103 |
3 | 9 |
| 104 |
4 | 16 |
| 105 |
(5 rows) |
| 106 |
|
| 107 |
select * from tcl_test_sequence(0,5) as a; |
| 108 |
a |
| 109 |
--- |
| 110 |
0 |
| 111 |
1 |
| 112 |
2 |
| 113 |
3 |
| 114 |
4 |
| 115 |
(5 rows) |
| 116 |
|
| 117 |
select 1, tcl_test_sequence(0,5); |
| 118 |
?column? | tcl_test_sequence |
| 119 |
----------+------------------- |
| 120 |
1 | 0 |
| 121 |
1 | 1 |
| 122 |
1 | 2 |
| 123 |
1 | 3 |
| 124 |
1 | 4 |
| 125 |
(5 rows) |
| 126 |
|
| 127 |
create function non_srf() returns int as $$return_next 1$$ language pltcl; |
| 128 |
select non_srf(); |
| 129 |
ERROR: return_next cannot be used in non-set-returning functions |
| 130 |
CONTEXT: while executing |
| 131 |
"return_next 1" |
| 132 |
(procedure "__PLTcl_proc_non_srf" line 2) |
| 133 |
invoked from within |
| 134 |
"__PLTcl_proc_non_srf" |
| 135 |
in PL/Tcl function non_srf() |
| 136 |
create function bad_record_srf(out a text, out b text) returns setof record as $$ |
| 137 |
return_next [list a] |
| 138 |
$$ language pltcl; |
| 139 |
select bad_record_srf(); |
| 140 |
ERROR: column name/value list must have even number of elements |
| 141 |
CONTEXT: while executing |
| 142 |
"return_next [list a]" |
| 143 |
(procedure "__PLTcl_proc_bad_record_srf" line 3) |
| 144 |
invoked from within |
| 145 |
"__PLTcl_proc_bad_record_srf" |
| 146 |
in PL/Tcl function bad_record_srf() |
| 147 |
create function bad_field_srf(out a text, out b text) returns setof record as $$ |
| 148 |
return_next [list a 1 b 2 cow 3] |
| 149 |
$$ language pltcl; |
| 150 |
select bad_field_srf(); |
| 151 |
ERROR: column name/value list contains nonexistent column name "cow" |
| 152 |
CONTEXT: while executing |
| 153 |
"return_next [list a 1 b 2 cow 3]" |
| 154 |
(procedure "__PLTcl_proc_bad_field_srf" line 3) |
| 155 |
invoked from within |
| 156 |
"__PLTcl_proc_bad_field_srf" |
| 157 |
in PL/Tcl function bad_field_srf() |
| 158 |
-- test composite and domain-over-composite results |
| 159 |
create function tcl_composite_result(int) returns T_comp1 as $$ |
| 160 |
return [list tkey tkey1 ref1 $1 ref2 ref22] |
| 161 |
$$ language pltcl; |
| 162 |
select tcl_composite_result(1001); |
| 163 |
tcl_composite_result |
| 164 |
-------------------------------------------- |
| 165 |
("tkey1 ",1001,"ref22 ") |
| 166 |
(1 row) |
| 167 |
|
| 168 |
select * from tcl_composite_result(1002); |
| 169 |
tkey | ref1 | ref2 |
| 170 |
------------+------+---------------------- |
| 171 |
tkey1 | 1002 | ref22 |
| 172 |
(1 row) |
| 173 |
|
| 174 |
create function tcl_dcomposite_result(int) returns d_comp1 as $$ |
| 175 |
return [list tkey tkey2 ref1 $1 ref2 ref42] |
| 176 |
$$ language pltcl; |
| 177 |
select tcl_dcomposite_result(1001); |
| 178 |
tcl_dcomposite_result |
| 179 |
-------------------------------------------- |
| 180 |
("tkey2 ",1001,"ref42 ") |
| 181 |
(1 row) |
| 182 |
|
| 183 |
select * from tcl_dcomposite_result(1002); |
| 184 |
tkey | ref1 | ref2 |
| 185 |
------------+------+---------------------- |
| 186 |
tkey2 | 1002 | ref42 |
| 187 |
(1 row) |
| 188 |
|
| 189 |
select * from tcl_dcomposite_result(-1); -- fail |
| 190 |
ERROR: value for domain d_comp1 violates check constraint "d_comp1_check" |
| 191 |
create function tcl_record_result(int) returns record as $$ |
| 192 |
return [list q1 sometext q2 $1 q3 moretext] |
| 193 |
$$ language pltcl; |
| 194 |
select tcl_record_result(42); -- fail |
| 195 |
ERROR: function returning record called in context that cannot accept type record |
| 196 |
select * from tcl_record_result(42); -- fail |
| 197 |
ERROR: a column definition list is required for functions returning "record" |
| 198 |
LINE 1: select * from tcl_record_result(42); |
| 199 |
^ |
| 200 |
select * from tcl_record_result(42) as (q1 text, q2 int, q3 text); |
| 201 |
q1 | q2 | q3 |
| 202 |
----------+----+---------- |
| 203 |
sometext | 42 | moretext |
| 204 |
(1 row) |
| 205 |
|
| 206 |
select * from tcl_record_result(42) as (q1 text, q2 int, q3 text, q4 int); |
| 207 |
q1 | q2 | q3 | q4 |
| 208 |
----------+----+----------+---- |
| 209 |
sometext | 42 | moretext | |
| 210 |
(1 row) |
| 211 |
|
| 212 |
select * from tcl_record_result(42) as (q1 text, q2 int, q4 int); -- fail |
| 213 |
ERROR: column name/value list contains nonexistent column name "q3" |
| 214 |
-- test quote |
| 215 |
select tcl_eval('quote foo bar'); |
| 216 |
ERROR: wrong # args: should be "quote string" |
| 217 |
CONTEXT: while executing |
| 218 |
"quote foo bar" |
| 219 |
("eval" body line 1) |
| 220 |
invoked from within |
| 221 |
"eval $1" |
| 222 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 223 |
invoked from within |
| 224 |
"__PLTcl_proc_tcl_eval_text {quote foo bar}" |
| 225 |
in PL/Tcl function tcl_eval(text) |
| 226 |
select tcl_eval('quote [format %c 39]'); |
| 227 |
tcl_eval |
| 228 |
---------- |
| 229 |
'' |
| 230 |
(1 row) |
| 231 |
|
| 232 |
select tcl_eval('quote [format %c 92]'); |
| 233 |
tcl_eval |
| 234 |
---------- |
| 235 |
\\ |
| 236 |
(1 row) |
| 237 |
|
| 238 |
-- Test argisnull |
| 239 |
select tcl_eval('argisnull'); |
| 240 |
ERROR: wrong # args: should be "argisnull argno" |
| 241 |
CONTEXT: while executing |
| 242 |
"argisnull" |
| 243 |
("eval" body line 1) |
| 244 |
invoked from within |
| 245 |
"eval $1" |
| 246 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 247 |
invoked from within |
| 248 |
"__PLTcl_proc_tcl_eval_text argisnull" |
| 249 |
in PL/Tcl function tcl_eval(text) |
| 250 |
select tcl_eval('argisnull 14'); |
| 251 |
ERROR: argno out of range |
| 252 |
CONTEXT: while executing |
| 253 |
"argisnull 14" |
| 254 |
("eval" body line 1) |
| 255 |
invoked from within |
| 256 |
"eval $1" |
| 257 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 258 |
invoked from within |
| 259 |
"__PLTcl_proc_tcl_eval_text {argisnull 14}" |
| 260 |
in PL/Tcl function tcl_eval(text) |
| 261 |
select tcl_eval('argisnull abc'); |
| 262 |
ERROR: expected integer but got "abc" |
| 263 |
CONTEXT: while executing |
| 264 |
"argisnull abc" |
| 265 |
("eval" body line 1) |
| 266 |
invoked from within |
| 267 |
"eval $1" |
| 268 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 269 |
invoked from within |
| 270 |
"__PLTcl_proc_tcl_eval_text {argisnull abc}" |
| 271 |
in PL/Tcl function tcl_eval(text) |
| 272 |
-- Test return_null |
| 273 |
select tcl_eval('return_null 14'); |
| 274 |
ERROR: wrong # args: should be "return_null " |
| 275 |
CONTEXT: while executing |
| 276 |
"return_null 14" |
| 277 |
("eval" body line 1) |
| 278 |
invoked from within |
| 279 |
"eval $1" |
| 280 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 281 |
invoked from within |
| 282 |
"__PLTcl_proc_tcl_eval_text {return_null 14}" |
| 283 |
in PL/Tcl function tcl_eval(text) |
| 284 |
-- Test spi_exec |
| 285 |
select tcl_eval('spi_exec'); |
| 286 |
ERROR: wrong # args: should be "spi_exec ?-count n? ?-array name? query ?loop body?" |
| 287 |
CONTEXT: while executing |
| 288 |
"spi_exec" |
| 289 |
("eval" body line 1) |
| 290 |
invoked from within |
| 291 |
"eval $1" |
| 292 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 293 |
invoked from within |
| 294 |
"__PLTcl_proc_tcl_eval_text spi_exec" |
| 295 |
in PL/Tcl function tcl_eval(text) |
| 296 |
select tcl_eval('spi_exec -count'); |
| 297 |
ERROR: missing argument to -count or -array |
| 298 |
CONTEXT: while executing |
| 299 |
"spi_exec -count" |
| 300 |
("eval" body line 1) |
| 301 |
invoked from within |
| 302 |
"eval $1" |
| 303 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 304 |
invoked from within |
| 305 |
"__PLTcl_proc_tcl_eval_text {spi_exec -count}" |
| 306 |
in PL/Tcl function tcl_eval(text) |
| 307 |
select tcl_eval('spi_exec -array'); |
| 308 |
ERROR: missing argument to -count or -array |
| 309 |
CONTEXT: while executing |
| 310 |
"spi_exec -array" |
| 311 |
("eval" body line 1) |
| 312 |
invoked from within |
| 313 |
"eval $1" |
| 314 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 315 |
invoked from within |
| 316 |
"__PLTcl_proc_tcl_eval_text {spi_exec -array}" |
| 317 |
in PL/Tcl function tcl_eval(text) |
| 318 |
select tcl_eval('spi_exec -count abc'); |
| 319 |
ERROR: expected integer but got "abc" |
| 320 |
CONTEXT: while executing |
| 321 |
"spi_exec -count abc" |
| 322 |
("eval" body line 1) |
| 323 |
invoked from within |
| 324 |
"eval $1" |
| 325 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 326 |
invoked from within |
| 327 |
"__PLTcl_proc_tcl_eval_text {spi_exec -count abc}" |
| 328 |
in PL/Tcl function tcl_eval(text) |
| 329 |
select tcl_eval('spi_exec query loop body toomuch'); |
| 330 |
ERROR: wrong # args: should be "query ?loop body?" |
| 331 |
CONTEXT: while executing |
| 332 |
"spi_exec query loop body toomuch" |
| 333 |
("eval" body line 1) |
| 334 |
invoked from within |
| 335 |
"eval $1" |
| 336 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 337 |
invoked from within |
| 338 |
"__PLTcl_proc_tcl_eval_text {spi_exec query loop body toomuch}" |
| 339 |
in PL/Tcl function tcl_eval(text) |
| 340 |
select tcl_eval('spi_exec "begin; rollback;"'); |
| 341 |
ERROR: pltcl: SPI_execute failed: SPI_ERROR_TRANSACTION |
| 342 |
CONTEXT: while executing |
| 343 |
"spi_exec "begin; rollback;"" |
| 344 |
("eval" body line 1) |
| 345 |
invoked from within |
| 346 |
"eval $1" |
| 347 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 348 |
invoked from within |
| 349 |
"__PLTcl_proc_tcl_eval_text {spi_exec "begin; rollback;"}" |
| 350 |
in PL/Tcl function tcl_eval(text) |
| 351 |
-- Test spi_execp |
| 352 |
select tcl_eval('spi_execp'); |
| 353 |
ERROR: missing argument to -count or -array |
| 354 |
CONTEXT: while executing |
| 355 |
"spi_execp" |
| 356 |
("eval" body line 1) |
| 357 |
invoked from within |
| 358 |
"eval $1" |
| 359 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 360 |
invoked from within |
| 361 |
"__PLTcl_proc_tcl_eval_text spi_execp" |
| 362 |
in PL/Tcl function tcl_eval(text) |
| 363 |
select tcl_eval('spi_execp -count'); |
| 364 |
ERROR: missing argument to -array, -count or -nulls |
| 365 |
CONTEXT: while executing |
| 366 |
"spi_execp -count" |
| 367 |
("eval" body line 1) |
| 368 |
invoked from within |
| 369 |
"eval $1" |
| 370 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 371 |
invoked from within |
| 372 |
"__PLTcl_proc_tcl_eval_text {spi_execp -count}" |
| 373 |
in PL/Tcl function tcl_eval(text) |
| 374 |
select tcl_eval('spi_execp -array'); |
| 375 |
ERROR: missing argument to -array, -count or -nulls |
| 376 |
CONTEXT: while executing |
| 377 |
"spi_execp -array" |
| 378 |
("eval" body line 1) |
| 379 |
invoked from within |
| 380 |
"eval $1" |
| 381 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 382 |
invoked from within |
| 383 |
"__PLTcl_proc_tcl_eval_text {spi_execp -array}" |
| 384 |
in PL/Tcl function tcl_eval(text) |
| 385 |
select tcl_eval('spi_execp -count abc'); |
| 386 |
ERROR: expected integer but got "abc" |
| 387 |
CONTEXT: while executing |
| 388 |
"spi_execp -count abc" |
| 389 |
("eval" body line 1) |
| 390 |
invoked from within |
| 391 |
"eval $1" |
| 392 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 393 |
invoked from within |
| 394 |
"__PLTcl_proc_tcl_eval_text {spi_execp -count abc}" |
| 395 |
in PL/Tcl function tcl_eval(text) |
| 396 |
select tcl_eval('spi_execp -nulls'); |
| 397 |
ERROR: missing argument to -array, -count or -nulls |
| 398 |
CONTEXT: while executing |
| 399 |
"spi_execp -nulls" |
| 400 |
("eval" body line 1) |
| 401 |
invoked from within |
| 402 |
"eval $1" |
| 403 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 404 |
invoked from within |
| 405 |
"__PLTcl_proc_tcl_eval_text {spi_execp -nulls}" |
| 406 |
in PL/Tcl function tcl_eval(text) |
| 407 |
select tcl_eval('spi_execp ""'); |
| 408 |
ERROR: invalid queryid '' |
| 409 |
CONTEXT: while executing |
| 410 |
"spi_execp """ |
| 411 |
("eval" body line 1) |
| 412 |
invoked from within |
| 413 |
"eval $1" |
| 414 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 415 |
invoked from within |
| 416 |
"__PLTcl_proc_tcl_eval_text {spi_execp ""}" |
| 417 |
in PL/Tcl function tcl_eval(text) |
| 418 |
-- test spi_prepare |
| 419 |
select tcl_eval('spi_prepare'); |
| 420 |
ERROR: wrong # args: should be "spi_prepare query argtypes" |
| 421 |
CONTEXT: while executing |
| 422 |
"spi_prepare" |
| 423 |
("eval" body line 1) |
| 424 |
invoked from within |
| 425 |
"eval $1" |
| 426 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 427 |
invoked from within |
| 428 |
"__PLTcl_proc_tcl_eval_text spi_prepare" |
| 429 |
in PL/Tcl function tcl_eval(text) |
| 430 |
select tcl_eval('spi_prepare a b'); |
| 431 |
ERROR: type "b" does not exist |
| 432 |
CONTEXT: while executing |
| 433 |
"spi_prepare a b" |
| 434 |
("eval" body line 1) |
| 435 |
invoked from within |
| 436 |
"eval $1" |
| 437 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 438 |
invoked from within |
| 439 |
"__PLTcl_proc_tcl_eval_text {spi_prepare a b}" |
| 440 |
in PL/Tcl function tcl_eval(text) |
| 441 |
select tcl_eval('spi_prepare a "b {"'); |
| 442 |
ERROR: unmatched open brace in list |
| 443 |
CONTEXT: while executing |
| 444 |
"spi_prepare a "b {"" |
| 445 |
("eval" body line 1) |
| 446 |
invoked from within |
| 447 |
"eval $1" |
| 448 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 449 |
invoked from within |
| 450 |
"__PLTcl_proc_tcl_eval_text spi_prepare\ a\ \"b\ \{\"" |
| 451 |
in PL/Tcl function tcl_eval(text) |
| 452 |
select tcl_error_handling_test($tcl$spi_prepare "select moo" []$tcl$); |
| 453 |
tcl_error_handling_test |
| 454 |
-------------------------------------- |
| 455 |
SQLSTATE: 42703 + |
| 456 |
condition: undefined_column + |
| 457 |
cursor_position: 8 + |
| 458 |
message: column "moo" does not exist+ |
| 459 |
statement: select moo |
| 460 |
(1 row) |
| 461 |
|
| 462 |
-- test full error text |
| 463 |
select tcl_error_handling_test($tcl$ |
| 464 |
spi_exec "DO $$ |
| 465 |
BEGIN |
| 466 |
RAISE 'my message' |
| 467 |
USING HINT = 'my hint' |
| 468 |
, DETAIL = 'my detail' |
| 469 |
, SCHEMA = 'my schema' |
| 470 |
, TABLE = 'my table' |
| 471 |
, COLUMN = 'my column' |
| 472 |
, CONSTRAINT = 'my constraint' |
| 473 |
, DATATYPE = 'my datatype' |
| 474 |
; |
| 475 |
END$$;" |
| 476 |
$tcl$); |
| 477 |
tcl_error_handling_test |
| 478 |
-------------------------------------------------------------- |
| 479 |
SQLSTATE: P0001 + |
| 480 |
column: my column + |
| 481 |
condition: raise_exception + |
| 482 |
constraint: my constraint + |
| 483 |
context: PL/pgSQL function inline_code_block line 3 at RAISE+ |
| 484 |
SQL statement "DO $$ + |
| 485 |
BEGIN + |
| 486 |
RAISE 'my message' + |
| 487 |
USING HINT = 'my hint' + |
| 488 |
, DETAIL = 'my detail' + |
| 489 |
, SCHEMA = 'my schema' + |
| 490 |
, TABLE = 'my table' + |
| 491 |
, COLUMN = 'my column' + |
| 492 |
, CONSTRAINT = 'my constraint' + |
| 493 |
, DATATYPE = 'my datatype' + |
| 494 |
; + |
| 495 |
END$$;" + |
| 496 |
datatype: my datatype + |
| 497 |
detail: my detail + |
| 498 |
hint: my hint + |
| 499 |
message: my message + |
| 500 |
schema: my schema + |
| 501 |
table: my table |
| 502 |
(1 row) |
| 503 |
|
| 504 |
-- verify tcl_error_handling_test() properly reports non-postgres errors |
| 505 |
select tcl_error_handling_test('moo'); |
| 506 |
tcl_error_handling_test |
| 507 |
---------------------------- |
| 508 |
invalid command name "moo" |
| 509 |
(1 row) |
| 510 |
|
| 511 |
-- test elog |
| 512 |
select tcl_eval('elog'); |
| 513 |
ERROR: wrong # args: should be "elog level msg" |
| 514 |
CONTEXT: while executing |
| 515 |
"elog" |
| 516 |
("eval" body line 1) |
| 517 |
invoked from within |
| 518 |
"eval $1" |
| 519 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 520 |
invoked from within |
| 521 |
"__PLTcl_proc_tcl_eval_text elog" |
| 522 |
in PL/Tcl function tcl_eval(text) |
| 523 |
select tcl_eval('elog foo bar'); |
| 524 |
ERROR: bad priority "foo": must be DEBUG, LOG, INFO, NOTICE, WARNING, ERROR, or FATAL |
| 525 |
CONTEXT: while executing |
| 526 |
"elog foo bar" |
| 527 |
("eval" body line 1) |
| 528 |
invoked from within |
| 529 |
"eval $1" |
| 530 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 531 |
invoked from within |
| 532 |
"__PLTcl_proc_tcl_eval_text {elog foo bar}" |
| 533 |
in PL/Tcl function tcl_eval(text) |
| 534 |
-- test forced error |
| 535 |
select tcl_eval('error "forced error"'); |
| 536 |
ERROR: forced error |
| 537 |
CONTEXT: while executing |
| 538 |
"error "forced error"" |
| 539 |
("eval" body line 1) |
| 540 |
invoked from within |
| 541 |
"eval $1" |
| 542 |
(procedure "__PLTcl_proc_tcl_eval_text" line 3) |
| 543 |
invoked from within |
| 544 |
"__PLTcl_proc_tcl_eval_text {error "forced error"}" |
| 545 |
in PL/Tcl function tcl_eval(text) |
| 546 |
-- test loop control in spi_exec[p] |
| 547 |
select tcl_spi_exec(true, 'break'); |
| 548 |
NOTICE: col1 1, col2 foo |
| 549 |
NOTICE: col1 2, col2 bar |
| 550 |
NOTICE: action: break |
| 551 |
NOTICE: end of function |
| 552 |
tcl_spi_exec |
| 553 |
-------------- |
| 554 |
|
| 555 |
(1 row) |
| 556 |
|
| 557 |
select tcl_spi_exec(true, 'continue'); |
| 558 |
NOTICE: col1 1, col2 foo |
| 559 |
NOTICE: col1 2, col2 bar |
| 560 |
NOTICE: action: continue |
| 561 |
NOTICE: col1 3, col2 baz |
| 562 |
NOTICE: end of function |
| 563 |
tcl_spi_exec |
| 564 |
-------------- |
| 565 |
|
| 566 |
(1 row) |
| 567 |
|
| 568 |
select tcl_spi_exec(true, 'error'); |
| 569 |
NOTICE: col1 1, col2 foo |
| 570 |
NOTICE: col1 2, col2 bar |
| 571 |
NOTICE: action: error |
| 572 |
ERROR: error message |
| 573 |
CONTEXT: while executing |
| 574 |
"error "error message"" |
| 575 |
invoked from within |
| 576 |
"spi_execp -array A $prep { |
| 577 |
elog NOTICE "col1 $A(col1), col2 $A(col2)" |
| 578 |
|
| 579 |
switch $A(col1) { |
| 580 |
2 { |
| 581 |
elog NOTICE "..." |
| 582 |
(procedure "__PLTcl_proc_tcl_spi_exec_boolean_text" line 6) |
| 583 |
invoked from within |
| 584 |
"__PLTcl_proc_tcl_spi_exec_boolean_text t error" |
| 585 |
in PL/Tcl function tcl_spi_exec(boolean,text) |
| 586 |
select tcl_spi_exec(true, 'return'); |
| 587 |
NOTICE: col1 1, col2 foo |
| 588 |
NOTICE: col1 2, col2 bar |
| 589 |
NOTICE: action: return |
| 590 |
tcl_spi_exec |
| 591 |
-------------- |
| 592 |
|
| 593 |
(1 row) |
| 594 |
|
| 595 |
select tcl_spi_exec(false, 'break'); |
| 596 |
NOTICE: col1 1, col2 foo |
| 597 |
NOTICE: col1 2, col2 bar |
| 598 |
NOTICE: action: break |
| 599 |
NOTICE: end of function |
| 600 |
tcl_spi_exec |
| 601 |
-------------- |
| 602 |
|
| 603 |
(1 row) |
| 604 |
|
| 605 |
select tcl_spi_exec(false, 'continue'); |
| 606 |
NOTICE: col1 1, col2 foo |
| 607 |
NOTICE: col1 2, col2 bar |
| 608 |
NOTICE: action: continue |
| 609 |
NOTICE: col1 3, col2 baz |
| 610 |
NOTICE: end of function |
| 611 |
tcl_spi_exec |
| 612 |
-------------- |
| 613 |
|
| 614 |
(1 row) |
| 615 |
|
| 616 |
select tcl_spi_exec(false, 'error'); |
| 617 |
NOTICE: col1 1, col2 foo |
| 618 |
NOTICE: col1 2, col2 bar |
| 619 |
NOTICE: action: error |
| 620 |
ERROR: error message |
| 621 |
CONTEXT: while executing |
| 622 |
"error "error message"" |
| 623 |
invoked from within |
| 624 |
"spi_exec -array A $query { |
| 625 |
elog NOTICE "col1 $A(col1), col2 $A(col2)" |
| 626 |
|
| 627 |
switch $A(col1) { |
| 628 |
2 { |
| 629 |
elog NOTICE "..." |
| 630 |
(procedure "__PLTcl_proc_tcl_spi_exec_boolean_text" line 31) |
| 631 |
invoked from within |
| 632 |
"__PLTcl_proc_tcl_spi_exec_boolean_text f error" |
| 633 |
in PL/Tcl function tcl_spi_exec(boolean,text) |
| 634 |
select tcl_spi_exec(false, 'return'); |
| 635 |
NOTICE: col1 1, col2 foo |
| 636 |
NOTICE: col1 2, col2 bar |
| 637 |
NOTICE: action: return |
| 638 |
tcl_spi_exec |
| 639 |
-------------- |
| 640 |
|
| 641 |
(1 row) |
| 642 |
|
| 643 |
-- test that we don't get confused by multiple funcs with same SQL name |
| 644 |
create schema tcls1; |
| 645 |
create function tcls1.somefunc(int) returns int as $$ |
| 646 |
return [expr $1 * 2] |
| 647 |
$$ language pltcl; |
| 648 |
create schema tcls2; |
| 649 |
create function tcls2.somefunc(int) returns int as $$ |
| 650 |
return [expr $1 * 3] |
| 651 |
$$ language pltcl; |
| 652 |
set search_path = tcls1; |
| 653 |
select tcls1.somefunc(11); |
| 654 |
somefunc |
| 655 |
---------- |
| 656 |
22 |
| 657 |
(1 row) |
| 658 |
|
| 659 |
set search_path = tcls2; |
| 660 |
select tcls2.somefunc(12); |
| 661 |
somefunc |
| 662 |
---------- |
| 663 |
36 |
| 664 |
(1 row) |
| 665 |
|
| 666 |
set search_path = tcls1; |
| 667 |
select tcls1.somefunc(13); |
| 668 |
somefunc |
| 669 |
---------- |
| 670 |
26 |
| 671 |
(1 row) |
| 672 |
|
| 673 |
reset search_path; |
| 674 |
-- test that it works to replace a function that's being executed |
| 675 |
create function replaceme(text) returns text as $p$ |
| 676 |
spi_exec { |
| 677 |
create or replace function replaceme(text) returns text as $$ |
| 678 |
return "$1 fum" |
| 679 |
$$ language pltcl; |
| 680 |
} |
| 681 |
spi_exec {select replaceme('foe') as inner} |
| 682 |
return "fee $1 $inner" |
| 683 |
$p$ language pltcl; |
| 684 |
select replaceme('fie'); |
| 685 |
replaceme |
| 686 |
----------------- |
| 687 |
fee fie foe fum |
| 688 |
(1 row) |
| 689 |
|
| 690 |
select replaceme('fie'); |
| 691 |
replaceme |
| 692 |
----------- |
| 693 |
fie fum |
| 694 |
(1 row) |
| 695 |
|
| 696 |
-- forcibly run the Tcl event loop for awhile, to check that we have not |
| 697 |
-- messed things up too badly by disabling the Tcl notifier subsystem |
| 698 |
select tcl_eval($$ |
| 699 |
unset -nocomplain ::tcl_vwait |
| 700 |
after 100 {set ::tcl_vwait 1} |
| 701 |
vwait ::tcl_vwait |
| 702 |
unset -nocomplain ::tcl_vwait$$); |
| 703 |
tcl_eval |
| 704 |
---------- |
| 705 |
|
| 706 |
(1 row) |
| 707 |
|