pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8568: PLPGSQL Documentation For CASE Is incorrect
4+ messages / 4 participants
[nested] [flat]

* BUG #8568: PLPGSQL Documentation For CASE Is incorrect
@ 2013-10-30 00:07  joshuadburns@hotmail.com
  0 siblings, 2 replies; 4+ messages in thread

From: joshuadburns@hotmail.com @ 2013-10-30 00:07 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8568
Logged by:          Joshua D. Burns
Email address:      joshuadburns@hotmail.com
PostgreSQL version: 9.3.1
Operating system:   Linux
Description:        

Documentation Sections Affected:
* 8.4: 38.6
* 9.0, 9.1 & 9.2: 39.6
* 9.3 & devel: 40.6


Example Documentation URL:
http://www.postgresql.org/docs/9.3/static/plpgsql-control-structures.html


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:


  ERROR:  syntax error at or near "CASE"
  LINE 9:   END CASE;


However if I use "END;" in place of "END CASE;", the script executes as
expected. This leads me to believe the documentation for "CASE" statements
across all current versions of the documentation, are incorrect.


=====================================
Example CASE statement with END CASE;
-------------------------------------
DO LANGUAGE "plpgsql" $BODY$
DECLARE my_var INTEGER := 2; BEGIN
  RAISE NOTICE
    '%',
    CASE
      WHEN my_var = 1 THEN 'one'
      WHEN my_var = 2 THEN 'two'
      WHEN my_var = 3 THEN 'three'
    END CASE;
END $BODY$;
=====================================
Results In Unexpected Behavior:
  ERROR:  syntax error at or near "CASE"
  LINE 9:   END CASE;


=====================================
Example CASE statement using END;
-------------------------------------
DO LANGUAGE "plpgsql" $BODY$
DECLARE my_var INTEGER := 2; BEGIN
  RAISE NOTICE
    '%',
    CASE
      WHEN my_var = 1 THEN 'one'
      WHEN my_var = 2 THEN 'two'
      WHEN my_var = 3 THEN 'three'
    END;
END $BODY$;
-------------------------------------
Results In Expected Behavior:
  NOTICE:  two


I haven't checked, but this could also affect IF statements, specifically
"END IF;" vs. "END;" as well.



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #8568: PLPGSQL Documentation For CASE Is incorrect
@ 2013-10-30 00:19  Tom Lane <tgl@sss.pgh.pa.us>
  parent: joshuadburns@hotmail.com
  1 sibling, 0 replies; 4+ messages in thread

From: Tom Lane @ 2013-10-30 00:19 UTC (permalink / raw)
  To: joshuadburns@hotmail.com; +Cc: pgsql-bugs

joshuadburns@hotmail.com writes:
> Every example within the PLPGSQL "control structures" documentation states
> that the proper syntax for closing a "CASE" statement is to use "END CASE;"

Which it is.

> =====================================
> Example CASE statement with END CASE;
> -------------------------------------
> DO LANGUAGE "plpgsql" $BODY$
> DECLARE my_var INTEGER := 2; BEGIN
>   RAISE NOTICE
>     '%',
>     CASE
>       WHEN my_var = 1 THEN 'one'
>       WHEN my_var = 2 THEN 'two'
>       WHEN my_var = 3 THEN 'three'
>     END CASE;
> END $BODY$;

This is not a case statement, it's a case expression (used within a RAISE
statement).  That's documented under the main SQL grammar, and there
you just say END.  Yeah, I know it's not terribly consistent.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #8568: PLPGSQL Documentation For CASE Is incorrect
@ 2013-10-30 00:29  David Johnston <polobo@yahoo.com>
  parent: joshuadburns@hotmail.com
  1 sibling, 1 reply; 4+ messages in thread

From: David Johnston @ 2013-10-30 00:29 UTC (permalink / raw)
  To: pgsql-bugs

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-tp57763...
Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #8568: PLPGSQL Documentation For CASE Is incorrect
@ 2013-10-30 03:18  Pavel Stehule <pavel.stehule@gmail.com>
  parent: David Johnston <polobo@yahoo.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Pavel Stehule @ 2013-10-30 03:18 UTC (permalink / raw)
  To: David Johnston <polobo@yahoo.com>; +Cc: pgsql-bugs

Dne 30.10.2013 1:29 "David Johnston" <polobo@yahoo.com> napsal(a):
>
> 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.

It is just wrong. Plpgsql statements cannot be nested inside expression.

Plpgsql doesn't know only expression statemenst yet, so first token is
statement reserved keyword ever.

>
> 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-tp57763...
> Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2013-10-30 03:18 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-10-30 00:07 BUG #8568: PLPGSQL Documentation For CASE Is incorrect joshuadburns@hotmail.com
2013-10-30 00:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2013-10-30 00:29 ` David Johnston <polobo@yahoo.com>
2013-10-30 03:18   ` Pavel Stehule <pavel.stehule@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox