Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YlAb3-00089T-Lx for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2015 06:26:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YlAb2-0008Rb-Lk for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2015 06:26:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YlAb1-0008RV-HZ for pgsql-hackers@postgresql.org; Thu, 23 Apr 2015 06:26:47 +0000 Received: from mail-pa0-f48.google.com ([209.85.220.48]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YlAau-0004gy-So for pgsql-hackers@postgresql.org; Thu, 23 Apr 2015 06:26:46 +0000 Received: by paboj16 with SMTP id oj16so9775173pab.0 for ; Wed, 22 Apr 2015 23:26:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:content-type:mime-version:content-transfer-encoding; bh=4YP7wZB63GS63kQfU11wAzffQ0qWALR3izjYDl9tdUU=; b=ev1Fpak1aa940ws6dLLoiv8fv0gTrBR/RoVDmjcCFddx297CHLslvXK0vvuSkSzDdG dF8YEgAZtsTKRwadIJKn2Y7x1i5qsxLOnv6YOKTm1eCDjvjZ3hdyzTmWCxZnPqda7qXr 1G7/sELOfFcQFScQl5r9NHwDFGp5DoR52hJ6RGfMG1RtQdYQxlotCD5C5VXO8fl5VDM1 Uc+oBSIa2deay1HxN1OoBgYPHv12lmLvpU+QCto8LlIL/AMDJRZQEtfgJiiXIFE0vdeC cS3iuM4cMC6VhOfnbnHllMjwf5l7kz2j499GUJDHn8wBeo7w38PmWUdPtCPKAvs/qIwc cF1Q== X-Gm-Message-State: ALoCoQlAq5p54niIPtP9qQYiW7Ab7cX5FLAsyyMf4PlcgxnmS4RgkIWfcasdxj3n/PmUm34ttrGM X-Received: by 10.66.229.9 with SMTP id sm9mr2399383pac.1.1429770399679; Wed, 22 Apr 2015 23:26:39 -0700 (PDT) Received: from [192.168.0.107] (c-69-181-249-16.hsd1.ca.comcast.net. [69.181.249.16]) by mx.google.com with ESMTPSA id gy1sm6887525pbc.55.2015.04.22.23.26.37 (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2015 23:26:38 -0700 (PDT) Message-ID: <1429770403.4604.22.camel@jeff-desktop> Subject: Re: [BUGS] Failure to coerce unknown type to specific type From: Jeff Davis To: "David G. Johnston" Cc: Tom Lane , PostgreSQL-development Date: Wed, 22 Apr 2015 23:26:43 -0700 In-Reply-To: References: <1430.1428543112@sss.pgh.pa.us> <1428560300.2845.45.camel@jeff-desktop> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.9 (--) 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 On Wed, 2015-04-22 at 20:35 -0700, David G. Johnston wrote: > But the fact that column "b" has the data type "unknown" is only a > warning - not an error. > I get an error: postgres=# SELECT ' '::text = 'a'; ?column? ---------- f (1 row) postgres=# SELECT a=b FROM (SELECT ''::text, ' ') x(a,b); ERROR: failed to find conversion function from unknown to text So that means the column reference "b" is treated differently than the literal. Here I don't mean a reference to an actual column of a real table, just an identifier ("b") that parses as a columnref. Creating the table gives you a warning (not an error), but I think that was a poor example for me to choose, and not important to my point. > > This seems to be a case of the common problem (or, at least recently > mentioned) where type conversion only deals with data and not context. > > > http://www.postgresql.org/message-id/CADx9qBmVPQvSH3 > +2cH4cwwPmphW1mE18e=WUmLFUC-QZ-t7Q6Q@mail.gmail.com > > I think that is a different problem. That's a runtime type conversion error (execution time), and I'm talking about something happening at parse analysis time. > > but this too works - which is why the implicit cast concept above > fails (I'm leaving it since the thought process may help in > understanding): > > > SELECT 1 = '1'; > > > From which I infer that an unknown literal is allowed to be fed > directly into a type's input function to facilitate a direct coercion. Yes, I believe that's what's happening. When we use an unknown literal, it's acting more like a value constructor and will pass it to the type input function. When it's a columnref, even if unknown, it tries to cast it and fails. But that is very confusing. In the example at the top of this email, it seems like the second query should be equivalent to the first, or even that postgres should be able to rewrite the second into the first. But the second query fails where the first succeeds. > At this point...backward compatibility? Backwards compatibility of what queries? I guess the ones that return unknowns to the client or create tables with unknown columns? > create table a(u) as select '1'; > > > WARNING: "column "u" has type "unknown"​ > DETAIL: Proceeding with relation creation anyway. > > > Related question: was there ever a time when the above failed instead > of just supplying a warning? Not that I recall. > ​My gut reaction is if you feel strongly enough to add some additional > documentation or warnings/hints/details related to this topic they > probably would get put in; but disallowing "unknown" as first-class > type is likely to fail to pass a cost-benefit evaluation. I'm not proposing that we eliminate unknown. I just think columnrefs and literals should behave consistently. If we really don't want unknown columnrefs, it seems like we could at least throw a better error. If we were starting from scratch, I'd also not return unknown to the client, but we have to worry about the backwards compatibility. > Distinguishing between "untyped" literals and "unknown type" literals > seems promising concept to aid in understanding the difference in the > face of not being able (or wanting) to actually change the behavior. Not sure I understand that proposal, can you elaborate? Regards, Jeff Davis -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers