Re: BUG #13829: Exponentiation operator is left-associative

From: Henrik Pauli <henrik(dot)pauli(at)uhusystems(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13829: Exponentiation operator is left-associative
Date: 2015-12-22 16:55:12
Message-ID: 56798070.40702@uhusystems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 22/12/15 17:00, Tom Lane wrote:
> henrik(dot)pauli(at)uhusystems(dot)com writes:
>> The convention with exponentation is the following (according to Wikipedia):
>> "Without parentheses to modify the order of calculation, by convention the
>> order is top-down, not bottom-up" -- in programming terms, it means that
>> exponentation is by default right-associative.
>> ...
>> However, PostgreSQL -- as indeed mentioned in the docs -- considers the
>> paren-less version more like the one where the left side is parenthesised:
> Yeah. I can't see us changing this. Aside from backwards-compatibility
> considerations, "^" is not so thoroughly identified with exponentiation
> that no-one would ever make a custom operator named "^" that did something
> else. Since operator precedence and associativity are determined solely
> by the operator name, right-to-left associativity would have to apply to
> such custom operators too, which would be mighty surprising if their
> semantics were something else.

The custom operator thing is one of those situations I didn't think of
and that's a reasonable problem there. That said, I guess the (few)
users with things like a^b^c in their code also find it "mighty
surprising" that it isn't a^(b^c). So one side is left scratching their
heads either way.

> However, pointing the issue out somewhere near Table 9-2. Mathematical
> Operators seems reasonable. The minimum change would just be to call it
> out in the table entry itself:
>
> Operator Description Example Result
> ...
> ^ exponentiation (associates left to right) 2.0 ^ 3.0 8
>
> Do you think that's sufficient?
>
> regards, tom lane

Might well be enough, not sure. Some parts of the documentation do come
with little "Note" boxes in the text (can't quite remember an exact
example, but I seem to remember there being such), which increase
visibility to such discrepancy more effectively. Might be worth a
sentence or two. I guess if there hasn't been a report before (no
idea), people just don't do this in Postgres and so haven't been bitten
by it at all.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2015-12-22 19:20:12 Re: BUG #13829: Exponentiation operator is left-associative
Previous Message Alvaro Herrera 2015-12-22 16:46:17 Re: BUG #13826: Error 10061