wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Started by Andreas Wenkover 16 years ago6 messagesdocs
Jump to latest
#1Andreas Wenk
a.wenk@netzmeister-st-pauli.de

Hi,

I find it a little confusing how 38.6.2.4. Simple CASE and 38.6.2.5.
Searched CASE is described. In Simple CASE is written

CASE search-expression
WHEN expression [,

and in 38.6.2.5. Searched CASE is written

CASE
WHEN boolean-expression

IMO speaking of a search-expression for the simple CASE and speaking of
a boolean-expression in between Searched Case is confusing because of
the use of the word "search". I would change it to that:

[snip]
38.6.2.4. Simple CASE

CASE
WHEN boolean-expression THEN
statements
[ WHEN boolean-expression THEN
statements
... ]
[ ELSE
statements ]
END CASE;

The simple form of CASE provides conditional execution based on truth of
boolean expressions. Each WHEN clause's boolean-expression is evaluated
in turn, until one is found that yields true. Then the corresponding
statements are executed, and then control passes to the next statement
after END CASE. (Subsequent WHEN expressions are not evaluated.) If no
true result is found, the ELSE statements are executed; but if ELSE is
not present, then a CASE_NOT_FOUND exception is raised.

[EXAMPLE ...]

38.6.2.5. Searched CASE

CASE search-expression
WHEN expression [, expression [ ... ]] THEN
statements
[ WHEN expression [, expression [ ... ]] THEN
statements
... ]
[ ELSE
statements ]
END CASE;

The searched form of CASE provides conditional execution based on
equality of operands. The search-expression is evaluated (once) and
successively compared to each expression in the WHEN clauses. If a match
is found, then the corresponding statements are executed, and then
control passes to the next statement after END CASE. (Subsequent WHEN
expressions are not evaluated.) If no match is found, the ELSE
statements are executed; but if ELSE is not present, then a
CASE_NOT_FOUND exception is raised.

[EXAMPLE ...]

[snip]

I moved 38.6.2.5 to 38.6.2.4 and changed the naming ...

Thoughts?

Cheers

Andy

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andreas Wenk (#1)
Re: wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Andreas Wenk <a.wenk@netzmeister-st-pauli.de> writes:

I find it a little confusing how 38.6.2.4. Simple CASE and 38.6.2.5.
Searched CASE is described. In Simple CASE is written

Hmm, it would be important to keep this in sync with the core-SQL
description of CASE, no? (Section 9.16.1)

I can't say that I think "simple CASE" and "searched CASE" are good
descriptions of the two forms, but just switching them doesn't make it
much better. And doing so would likely create as much confusion as
it eliminates. Can we come up with some other phrases?

regards, tom lane

#3Andreas Wenk
a.wenk@netzmeister-st-pauli.de
In reply to: Tom Lane (#2)
Re: wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Tom Lane wrote:

Hmm, it would be important to keep this in sync with the core-SQL
description of CASE, no? (Section 9.16.1)

yes. And there is written "general" form and "simple" form. I like that.

I can't say that I think "simple CASE" and "searched CASE" are good
descriptions of the two forms, but just switching them doesn't make it
much better. And doing so would likely create as much confusion as
it eliminates. Can we come up with some other phrases?

IMO it should be the same like in 9.16.1 - a "general" form and a
"simple" form. Then changing both sections would be ok, because in
9.16.1 the simple form is mentioned after the general form.

Would it be correct to change it in this direction - or is this
logically wrong (change expression to value):

38.6.2.4. Simple CASE

CASE expression
WHEN value [, value [ ... ]] THEN
statements
[ WHEN value [, value [ ... ]] THEN
statements
... ]
[ ELSE
statements ]
END CASE;

Maybe it could also be value-expression ... but that I don't like that much.

Then we could go further with this:

38.6.2.5. General CASE

CASE
WHEN boolean-expression THEN
statements
[ WHEN boolean-expression THEN
statements
... ]
[ ELSE
statements ]
END CASE;

The general form of CASE provides conditional execution based on truth
of boolean expressions. ...

I think with these changes, 9.16.1 and this two sections are working
together

Cheers

Andy

P.S.: I can provide a patch with the changes if we discussed it and are
willing to make a change

#4Andreas Wenk
a.wenk@netzmeister-st-pauli.de
In reply to: Andreas Wenk (#3)
Re: wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Andreas Wenk schrieb:

Tom Lane wrote:

Hmm, it would be important to keep this in sync with the core-SQL
description of CASE, no? (Section 9.16.1)

yes. And there is written "general" form and "simple" form. I like that.

I can't say that I think "simple CASE" and "searched CASE" are good
descriptions of the two forms, but just switching them doesn't make it
much better. And doing so would likely create as much confusion as
it eliminates. Can we come up with some other phrases?

IMO it should be the same like in 9.16.1 - a "general" form and a
"simple" form. Then changing both sections would be ok, because in
9.16.1 the simple form is mentioned after the general form.

Would it be correct to change it in this direction - or is this
logically wrong (change expression to value):

38.6.2.4. Simple CASE

CASE expression
WHEN value [, value [ ... ]] THEN
statements
[ WHEN value [, value [ ... ]] THEN
statements
... ]
[ ELSE
statements ]
END CASE;

Maybe it could also be value-expression ... but that I don't like that
much.

Then we could go further with this:

38.6.2.5. General CASE

CASE
WHEN boolean-expression THEN
statements
[ WHEN boolean-expression THEN
statements
... ]
[ ELSE
statements ]
END CASE;

The general form of CASE provides conditional execution based on truth
of boolean expressions. ...

I think with these changes, 9.16.1 and this two sections are working
together

Cheers

Andy

P.S.: I can provide a patch with the changes if we discussed it and are
willing to make a change

Hi,

before building a patch it would be nice to hear, if my approach to change the docu here
is a good one ...

Thanks

Andy

#5Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Andreas Wenk (#3)
Re: wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Andreas Wenk wrote:

Tom Lane wrote:

Hmm, it would be important to keep this in sync with the core-SQL
description of CASE, no? (Section 9.16.1)

yes. And there is written "general" form and "simple" form. I like that.

I can't say that I think "simple CASE" and "searched CASE" are good
descriptions of the two forms, but just switching them doesn't make it
much better. And doing so would likely create as much confusion as
it eliminates. Can we come up with some other phrases?

IMO it should be the same like in 9.16.1 - a "general" form and a
"simple" form. Then changing both sections would be ok, because in
9.16.1 the simple form is mentioned after the general form.

"simple case" and "searched case" is SQL/PSM's terminology. I'm not
sure it's necessarily a good idea to deviate from that. See SQL part 4,
13.6 <case statement>:

Function
Provide conditional execution based on truth of <search condition>s or on equality of operands.

Format
<case statement> ::=
<simple case statement>
| <searched case statement>
<simple case statement> ::=
CASE <case operand>
<simple case statement when clause>...
[ <case statement else clause> ]
END CASE
<searched case statement> ::=
CASE <searched case statement when clause>...
[ <case statement else clause> ]
END CASE
<simple case statement when clause> ::=
WHEN <when operand list>
THEN <SQL statement list>
<searched case statement when clause> ::=
WHEN <search condition>
THEN <SQL statement list>
<case statement else clause> ::= ELSE <SQL statement list>

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

#6Andreas Wenk
a.wenk@netzmeister-st-pauli.de
In reply to: Alvaro Herrera (#5)
Re: wording for 38.6.2.4. Simple CASE and 38.6.2.5. Searched CASE

Alvaro Herrera schrieb:

"simple case" and "searched case" is SQL/PSM's terminology. I'm not
sure it's necessarily a good idea to deviate from that. See SQL part 4,
13.6 <case statement>:

Function
Provide conditional execution based on truth of <search condition>s or on equality of operands.

Format
<case statement> ::=
<simple case statement>
| <searched case statement>
<simple case statement> ::=
CASE <case operand>
<simple case statement when clause>...
[ <case statement else clause> ]
END CASE
<searched case statement> ::=
CASE <searched case statement when clause>...
[ <case statement else clause> ]
END CASE
<simple case statement when clause> ::=
WHEN <when operand list>
THEN <SQL statement list>
<searched case statement when clause> ::=
WHEN <search condition>
THEN <SQL statement list>
<case statement else clause> ::= ELSE <SQL statement list>

Agreed ... using the standard terminology is better (as Tom also mentioned already).

Cheers

Andy