Thread: ONLY with parentheses

ONLY with parentheses

From
Peter Eisentraut
Date:
While working on TRUNCATE with ONLY, I said to myself, hmm, when writing

TRUNCATE ONLY a, b

it might be a bit confusing whether the ONLY refers to a or both a and 
b.  Then I noticed that the SQL standard requires parentheses, like

TRUNCATE ONLY (a), b

which is clearer.  While we support that in gram.y, I don't see it 
anywhere in the documentation.

Should we document this and emphasize it as having more clarity?


Re: ONLY with parentheses

From
Alvaro Herrera
Date:
Peter Eisentraut wrote:
> While working on TRUNCATE with ONLY, I said to myself, hmm, when writing
>
> TRUNCATE ONLY a, b
>
> it might be a bit confusing whether the ONLY refers to a or both a and  
> b.  Then I noticed that the SQL standard requires parentheses, like
>
> TRUNCATE ONLY (a), b
>
> which is clearer.

Hmm, if I want to truncate only both (or is that "both only"?), what do
I have to do?

TRUNCATE ONLY (a), ONLY (b)
or
TRUNCATE ONLY (a, b)

Also, does this work?
TRUNCATE a, ONLY (b)

It's still not clear whether 
TRUNCATE ONLY a, b
means to truncate both only, or only a only.

If only this was clearer ... if it was up to me, the ONLY keywords would
be inside the parentheses,
TRUNCATE (ONLY a), b
Now that is clear.  What the hell do I know anyway.

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


Re: ONLY with parentheses

From
Cédric Villemain
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Peter Eisentraut a écrit :
> While working on TRUNCATE with ONLY, I said to myself, hmm, when writing
> 
> TRUNCATE ONLY a, b
> 
> it might be a bit confusing whether the ONLY refers to a or both a and
> b.  Then I noticed that the SQL standard requires parentheses, like
> 
> TRUNCATE ONLY (a), b
> 
> which is clearer.  While we support that in gram.y, I don't see it
> anywhere in the documentation.
> 
> Should we document this and emphasize it as having more clarity?
> 

+1

- --
Cédric Villemain
Administrateur de Base de Données
Cel: +33 (0)6 74 15 56 53
http://dalibo.com - http://dalibo.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAklmA7wACgkQo/dppWjpEvxpcwCgyAA9OxtUN4X51EwuRmtMtGe+
Tm4AnAnjDzyc3roMZGFOhQWodOzueX1n
=TJ9x
-----END PGP SIGNATURE-----


Re: ONLY with parentheses

From
Tom Lane
Date:
Alvaro Herrera <alvherre@commandprompt.com> writes:
> Peter Eisentraut wrote:
>> Then I noticed that the SQL standard requires parentheses, like
>> 
>> TRUNCATE ONLY (a), b
>> 
>> which is clearer.

> Hmm, if I want to truncate only both (or is that "both only"?), what do
> I have to do?

> TRUNCATE ONLY (a, b)

Yeah.  To me those parentheses look more like redundant parentheses,
eg writing 2 + (2) instead of just 2 + 2.  If you consider that they're
not redundant then it becomes a fair question why Alvaro's multiple-
elements syntax doesn't work.

In the end what you have to point out is that ONLY binds tighter than
comma.  I don't think that parens where the committee put them help
resolve that at all.
        regards, tom lane