I’m porting database schema tests from sql/plpgsql to Java/JDBC. But here is a test case I can’t figure out how to test. As I can guess, this test tries to insert some row to a table, and expects SPECIAL_EXCEPTION to be thrown. If it’s thrown, the test passes, if other exception or no exception is thrown, the test fails. So the question: in the perspective of java.sql.Connection/Statement/ResultSet how to precisely test this?
begin;
do language plpgsql $$
declare
begin
begin
INSERT INTO table (
name,
blah...
) VALUES (
'Test Player ',
blah...
);
exception
when sqlstate 'SPECIAL_EXCEPTION' then
return;
when others then
raise info 'exception SPECIAL_EXCEPTION failed, invalid sqlstate';
raise;
end;
raise exception 'exception SPECIAL_EXCEPTION failed, no error thrown';
end;
$$;
commit;
If I got you right, then what you want is: