joshuadburns wrote
> Every example within the PLPGSQL "control structures" documentation states
> that the proper syntax for closing a "CASE" statement is to use "END
> CASE;"
> however in reality, on every version of PostgreSQL I can my hands on, "END
> CASE;" throws the following exception:
User error, though understandable.
pl/pgsql CASE requires "END CASE", SQL CASE just uses "END"
DO $$
DECLARE val integer;
BEGIN
val := 2;
CASE val
WHEN 1 THEN RAISE NOTICE 'Got 1';
WHEN 2 THEN RAISE NOTICE 'Got 2';
END CASE;
END;
$$;
Your examples were making use of SQL "CASE" expressions which do not accept
"END CASE" but "END".
A pl/pgsql CASE must be the first token of an expression (using the term
loosely) since its purpose is to act as flow-control. The sames goes for
IF.
There are a number of constructs and keywords in pl/pgsql that behave
slightly differently than their counter-parts in pure SQL.
David J.
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/BUG-8568-PLPGSQL-Documentation-For-CASE-Is-incorrect-tp5776314p5776318.html
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.