Seaquel
PostgreSQL error code

PostgreSQL error P0004

P0004 is the SQLSTATE PostgreSQL reports for assert failure, in class P0, PL/pgSQL Error.

SQLSTATEP0004
Condition nameassert_failure
ClassP0 — PL/pgSQL Error

Reproduce it, then fix it

ASSERT raises P0004 with its message when its condition is false; here the assumption about the data was wrong. Assertions are for catching bugs, and plpgsql.check_asserts = off disables them, so don’t rely on them for validation. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

DO $$
BEGIN
  ASSERT (SELECT count(*) FROM products) = 0, 'expected no products';
END $$;
DO $$
BEGIN
  ASSERT (SELECT count(*) FROM products WHERE price < 0) = 0, 'found a negative price';
END $$;

Source: PostgreSQL documentation, Appendix A