PostgreSQL error code
PostgreSQL error P0001
P0001 is the SQLSTATE PostgreSQL reports for raise exception, in class P0, PL/pgSQL Error.
| SQLSTATE | P0001 |
|---|---|
| Condition name | raise_exception |
| Class | P0 — PL/pgSQL Error |
Reproduce it, then fix it
P0001 is the code for RAISE EXCEPTION when no other code is given, so the message comes from your own function or trigger. Here reserve_stock refuses to reserve more than is in stock. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
SELECT reserve_stock(2, 500);
SELECT reserve_stock(2, 5);