1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-27 21:43:08 +03:00

Add an ASSERT statement in plpgsql.

This is meant to make it easier to insert simple debugging cross-checks
in plpgsql functions.

Pavel Stehule, reviewed by Jim Nasby
This commit is contained in:
Tom Lane
2015-03-25 19:05:20 -04:00
parent 83ff1618bc
commit a4847fc3ef
10 changed files with 316 additions and 16 deletions

View File

@@ -4217,3 +4217,51 @@ select outer_outer_func(20);
drop function outer_outer_func(int);
drop function outer_func(int);
drop function inner_func(int);
--
-- Test ASSERT
--
do $$
begin
assert 1=1; -- should succeed
end;
$$;
do $$
begin
assert 1=0; -- should fail
end;
$$;
do $$
begin
assert NULL; -- should fail
end;
$$;
-- check controlling GUC
set plpgsql.check_asserts = off;
do $$
begin
assert 1=0; -- won't be tested
end;
$$;
reset plpgsql.check_asserts;
-- test custom message
do $$
declare var text := 'some value';
begin
assert 1=0, format('assertion failed, var = "%s"', var);
end;
$$;
-- ensure assertions are not trapped by 'others'
do $$
begin
assert 1=0, 'unhandled assertion';
exception when others then
null; -- do nothing
end;
$$;