Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aBRj8-0006Ni-5O for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Dec 2015 18:32:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aBRj7-0006f7-NP for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Dec 2015 18:32:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aBQDU-0002QZ-O1 for pgsql-bugs@postgresql.org; Tue, 22 Dec 2015 16:55:16 +0000 Received: from katapult.uhulinux.hu ([195.228.155.101]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aBQDS-0000rp-4G for pgsql-bugs@postgresql.org; Tue, 22 Dec 2015 16:55:16 +0000 Received: from [172.16.1.140] (unknown [82.150.48.146]) by katapult.uhulinux.hu (Postfix) with ESMTPSA id AB7EA2534D; Tue, 22 Dec 2015 17:55:12 +0100 (CET) Subject: Re: BUG #13829: Exponentiation operator is left-associative To: Tom Lane References: <20151222140213.2675.849@wrigleys.postgresql.org> <14107.1450800047@sss.pgh.pa.us> Cc: pgsql-bugs@postgresql.org From: Henrik Pauli Message-ID: <56798070.40702@uhusystems.com> Date: Tue, 22 Dec 2015 17:55:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <14107.1450800047@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 22/12/15 17:00, Tom Lane wrote: > henrik.pauli@uhusystems.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. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs