Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ayjLT-00079d-K9 for pgsql-sql@arkaria.postgresql.org; Fri, 06 May 2016 17:15:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ayjLS-0008RH-6G for pgsql-sql@arkaria.postgresql.org; Fri, 06 May 2016 17:15:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ayjKV-0007Gz-CQ for pgsql-sql@postgresql.org; Fri, 06 May 2016 17:14:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ayjKT-0006tw-3j for pgsql-sql@postgresql.org; Fri, 06 May 2016 17:14:18 +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 u46HEDx9006976; Fri, 6 May 2016 13:14:13 -0400 From: Tom Lane To: "David G. Johnston" cc: Adrian Klaver , Michael Moore , postgres list Subject: Re: weird error message In-reply-to: References: <5722.1462552524@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Fri, 06 May 2016 10:00:57 -0700" Date: Fri, 06 May 2016 13:14:13 -0400 Message-ID: <6975.1462554853@sss.pgh.pa.us> X-Pg-Spam-Score: -4.0 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org "David G. Johnston" writes: > On Fri, May 6, 2016 at 9:35 AM, Tom Lane wrote: >> I think there's a rough consensus that it'd be okay to resolve unknown to >> text at the time that the subquery is parsed, if there's no reason to >> resolve it to something else. > ​I'm not sure that buys us a lot here... > SELECT case when dt IS NOT NULL then dt else i end FROM (SELECT null AS dt, 1 AS i) q; > failed to find conversion function from unknown to integer > SELECT case when dt IS NOT NULL then dt else i end FROM (SELECT '2'::text AS dt, 1 AS i) q; > ​SQL Error: ERROR: CASE types integer and text cannot be matched Well, you're right that that type of situation isn't going to "just work"; the user is going to have to cast the null explicitly, because I do not think it's reasonable to expect the system to guess that resolving the null as integer is what's needed. The point is to give a less opaque error message, and I think the latter error message is much better than what you get now. Also, defaulting to text is what happens in some related cases, notably SELECT case when dt IS NOT NULL then dt else i end FROM (SELECT DISTINCT null AS dt, 1 AS i) q; ERROR: CASE types integer and text cannot be matched In this case we resolved the unknown as text so that the DISTINCT could have some well-defined behavior. An ORDER BY targeting that column would do the same. So IMV it's already surprising that we don't resolve the unknown as text without those things. > I'm not certain why we wouldn't just add implicit casts from unknown to > other types. Because that would involve *far* more widespread, and less principled, changes in behavior. Implicit casts affect every part of the language, whereas the actual problem here is restricted to "what's the type of this sub-select output column?". > I'm willing to go read where this option has been discussed and dismissed - > just point me in the right direction please. It's come up repeatedly, though I do not have time right now to search the archives. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql