Is there a way to
ASSERT in PL/pgSQL, but for an exception rather than a condition? i.e. assert that "violates X constraint" will happen.
The closest I could get was:
DECLARE xc integer DEFAULT 0;
INSERT INTO [...];
RAISE EXCEPTION 'Should not make it this far';
WHEN integrity_constraint_violation THEN
RAISE NOTICE 'Caught expected integrity violation';
xc := xc + 1;
ASSERT ((SELECT xc) = 1);
This does the job(-ish). If I could specify the type of constraint violation that would be helpful.
Second part of question: how could I wrap this (or similar) into a macro / custom assert function?