@@ -2418,28 +2418,30 @@ drop type eitype cascade;
2418
2418
--
2419
2419
-- SQLSTATE and SQLERRM test
2420
2420
--
2421
- -- should fail: SQLSTATE and SQLERRM are only in defined EXCEPTION
2422
- -- blocks
2423
- create function excpt_test() returns void as $$
2421
+ create function excpt_test1() returns void as $$
2424
2422
begin
2425
2423
raise notice '% %', sqlstate, sqlerrm;
2426
2424
end; $$ language plpgsql;
2427
- ERROR: syntax error at or near "sqlstate" at character 79
2428
- LINE 3: raise notice '% %', sqlstate, sqlerrm;
2429
- ^
2430
- -- should fail
2431
- create function excpt_test() returns void as $$
2425
+ -- should fail: SQLSTATE and SQLERRM are only in defined EXCEPTION
2426
+ -- blocks
2427
+ select excpt_test1();
2428
+ ERROR: column "sqlstate" does not exist
2429
+ CONTEXT: SQL statement "SELECT sqlstate"
2430
+ PL/pgSQL function "excpt_test1" line 2 at raise
2431
+ create function excpt_test2() returns void as $$
2432
2432
begin
2433
2433
begin
2434
2434
begin
2435
2435
raise notice '% %', sqlstate, sqlerrm;
2436
2436
end;
2437
2437
end;
2438
2438
end; $$ language plpgsql;
2439
- ERROR: syntax error at or near "sqlstate" at character 108
2440
- LINE 5: raise notice '% %', sqlstate, sqlerrm;
2441
- ^
2442
- create function excpt_test() returns void as $$
2439
+ -- should fail
2440
+ select excpt_test2();
2441
+ ERROR: column "sqlstate" does not exist
2442
+ CONTEXT: SQL statement "SELECT sqlstate"
2443
+ PL/pgSQL function "excpt_test2" line 4 at raise
2444
+ create function excpt_test3() returns void as $$
2443
2445
begin
2444
2446
begin
2445
2447
raise exception 'user exception';
@@ -2458,14 +2460,34 @@ begin
2458
2460
raise notice '% %', sqlstate, sqlerrm;
2459
2461
end;
2460
2462
end; $$ language plpgsql;
2461
- select excpt_test ();
2463
+ select excpt_test3 ();
2462
2464
NOTICE: caught exception P0001 user exception
2463
2465
NOTICE: P0001 user exception
2464
2466
NOTICE: caught exception 22012 division by zero
2465
2467
NOTICE: P0001 user exception
2466
- excpt_test
2467
- ------------
2468
+ excpt_test3
2469
+ -------------
2470
+
2471
+ (1 row)
2472
+
2473
+ drop function excpt_test1();
2474
+ drop function excpt_test2();
2475
+ drop function excpt_test3();
2476
+ -- parameters of raise stmt can be expressions
2477
+ create function raise_exprs() returns void as $$
2478
+ declare
2479
+ a integer[] = '{10,20,30}';
2480
+ c varchar = 'xyz';
2481
+ i integer;
2482
+ begin
2483
+ i := 2;
2484
+ raise notice '%; %; %; %; %; %', a, a[i], c, (select c || 'abc'), row(10,'aaa',NULL,30), NULL;
2485
+ end;$$ language plpgsql;
2486
+ select raise_exprs();
2487
+ NOTICE: {10,20,30}; 20; xyz; xyzabc; (10,aaa,,30); <NULL>
2488
+ raise_exprs
2489
+ -------------
2468
2490
2469
2491
(1 row)
2470
2492
2471
- drop function excpt_test ();
2493
+ drop function raise_exprs ();
0 commit comments