Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fTq6O-0008Gy-Fd for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Jun 2018 14:53:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fTq6K-00056m-Th for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Jun 2018 14:53:20 +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.89) (envelope-from ) id 1fTq6K-00056b-N9 for pgsql-bugs@lists.postgresql.org; Fri, 15 Jun 2018 14:53:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fTq6H-0000go-Je for pgsql-bugs@postgresql.org; Fri, 15 Jun 2018 14:53:20 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w5FErDPJ032583; Fri, 15 Jun 2018 10:53:13 -0400 From: Tom Lane To: Neil Conway cc: pgsql-bugs@postgresql.org Subject: Re: row_to_json(), NULL values, and AS In-reply-to: <18365.1529018904@sss.pgh.pa.us> References: <18365.1529018904@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 14 Jun 2018 19:28:24 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32581.1529074393.1@sss.pgh.pa.us> Date: Fri, 15 Jun 2018 10:53:13 -0400 Message-ID: <32582.1529074393@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Neil Conway writes: >> The following behavior does not seem self-consistent to me: > Likewise. Oh! What is actually happening is (1) With no explicit alias, the column name of the sub-select's second output column is chosen to be "row_to_json". (2) That makes the outer query's notation row_to_json(x) ambiguous: it could be a function-syntax reference to the column x.row_to_json. (3) As it happens, the column interpretation is chosen when it's ambiguous (cf ParseComplexProjection). I'm a bit hesitant to muck with this behavior, given that it's stood for ~20 years. However, if we did want to touch it, maybe the right thing would be to give up the absolutist position that f(x) and x.f are exactly interchangeable. We could say instead that we prefer the function interpretation if function syntax is used, and the column interpretation if column syntax is used. I don't know how likely that is to break existing apps ... perhaps not very, but I wouldn't risk back-patching it in any case. regards, tom lane