PostgreSQL error code
PostgreSQL error 20000
20000 is the SQLSTATE PostgreSQL reports for case not found, in class 20, Case Not Found.
| SQLSTATE | 20000 |
|---|---|
| Condition name | case_not_found |
| Class | 20 — 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 $$;