This is from the official documentation (http://www.postgresql.org/docs/9.4/static/plpgsql-control-structures.html)
and two forms of CASE:
CASE ... WHEN ... THEN ... ELSE ... END CASE
CASE WHEN ... THEN ... ELSE ... END CASE
This doesn't work:
select case when 1 < 2 then 'a' else 'b' end case from pg_database limit 1;
It works with end
instead of end case
, though:
select case when 1 < 2 then 'a' else 'b' end from pg_database limit 1;
This is with PostgreSQL 9.4.6.
Why doesn't the syntax in the official docs match the syntax that the server apparently requires?