Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVkxF-00054h-VZ for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Jul 2017 20:43:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dVkxE-0006S6-T1 for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Jul 2017 20:43: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.84_2) (envelope-from ) id 1dVkvi-0003lW-8h for pgsql-hackers@postgresql.org; Thu, 13 Jul 2017 20:41:46 +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.84_2) (envelope-from ) id 1dVkvf-0004uT-J1 for pgsql-hackers@postgresql.org; Thu, 13 Jul 2017 20:41:45 +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 v6DKffeO022068; Thu, 13 Jul 2017 16:41:41 -0400 From: Tom Lane To: "David G. Johnston" cc: "pgsql-hackers@postgresql.org" Subject: Re: CAST vs :: In-reply-to: References: <10477.1499970459@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Thu, 13 Jul 2017 12:27:26 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22066.1499978501.1@sss.pgh.pa.us> Date: Thu, 13 Jul 2017 16:41:41 -0400 Message-ID: <22067.1499978501@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org "David G. Johnston" writes: > On Thursday, July 13, 2017, Tom Lane wrote: >> Maybe we can hack ruleutils to use >> the CAST syntax only in this specific context. > Given the lack of complaints, and ubiquity of ::, this would seem ideal > and sufficient. While there is something to be said for using standard > compliant syntax changing just this like doesn't seem like it would move > the goalposts meaningfully. Hm, it's worse than I thought: the argument of the CAST expression needn't be a function call at all, and on top of that, the parser will throw away a no-op cast altogether. So for example: regression=# create view vvc as select * from cast(1+2 as int) c(x); CREATE VIEW regression=# \d+ vvc View "public.vvc" Column | Type | Collation | Nullable | Default | Storage | Description --------+---------+-----------+----------+---------+---------+------------- x | integer | | | | plain | View definition: SELECT c.x FROM 1 + 2 c(x); To make the world safe for this behavior by extending the grammar, we'd have to be prepared to accept an arbitrary a_expr, without even surrounding parentheses, as a FROM item. I don't think there's much chance of making that work without grammar conflicts, and even if we managed, the SQL committee would probably find a way to break it with some future feature addition. So what I'm now thinking is to make ruleutils.c look at the expression in an RTE_FUNCTION FROM item and see if it will decompile as something with the syntax of a function call. If not, or if there's any doubt, emit a dummy CAST(... AS sametype) around it. That would cause the above example to come out the way it went in. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers