Seaquel
PostgreSQL error code

PostgreSQL error 20000

20000 is the SQLSTATE PostgreSQL reports for case not found, in class 20, Case Not Found.

SQLSTATE20000
Condition namecase_not_found
Class20 — Case Not Found

Reproduce it, then fix it

A PL/pgSQL CASE statement with no ELSE raises this when none of its WHEN branches match. A CASE expression in plain SQL returns NULL instead, so this only shows up in functions and DO blocks. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

DO $$
DECLARE
  status text := 'refunded';
BEGIN
  CASE status
    WHEN 'pending' THEN RAISE NOTICE 'waiting';
    WHEN 'shipped' THEN RAISE NOTICE 'on its way';
  END CASE;
END $$;
DO $$
DECLARE
  status text := 'refunded';
BEGIN
  CASE status
    WHEN 'pending' THEN RAISE NOTICE 'waiting';
    WHEN 'shipped' THEN RAISE NOTICE 'on its way';
    ELSE RAISE NOTICE 'unhandled status: %', status;
  END CASE;
END $$;

Source: PostgreSQL documentation, Appendix A