Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YlNAD-0004wK-OQ for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2015 19:51:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YlNAB-0001b2-Sd for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2015 19:51:55 +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 1YlN85-0007MP-Q4 for pgsql-hackers@postgresql.org; Thu, 23 Apr 2015 19:49:45 +0000 Received: from mail-bn1bon0069.outbound.protection.outlook.com ([157.56.111.69] helo=na01-bn1-obe.outbound.protection.outlook.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1YlN81-00022H-HN for pgsql-hackers@postgresql.org; Thu, 23 Apr 2015 19:49:43 +0000 Authentication-Results: postgresql.org; dkim=none (message not signed) header.d=none; Received: from decina.local (70.113.16.71) by CY1PR11MB0681.namprd11.prod.outlook.com (25.163.236.19) with Microsoft SMTP Server (TLS) id 15.1.148.16; Thu, 23 Apr 2015 19:49:34 +0000 Message-ID: <55394CC9.5050703@BlueTreble.com> Date: Thu, 23 Apr 2015 14:49:29 -0500 From: Jim Nasby User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Kyotaro HORIGUCHI , CC: , , Subject: Re: [BUGS] Failure to coerce unknown type to specific type References: <20150423.173144.97709612.horiguchi.kyotaro@lab.ntt.co.jp> <20150423.173535.202061455.horiguchi.kyotaro@lab.ntt.co.jp> <20150423.190749.87287279.horiguchi.kyotaro@lab.ntt.co.jp> In-Reply-To: <20150423.190749.87287279.horiguchi.kyotaro@lab.ntt.co.jp> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [70.113.16.71] X-ClientProxiedBy: BLUPR08CA0039.namprd08.prod.outlook.com (10.141.200.19) To CY1PR11MB0681.namprd11.prod.outlook.com (25.163.236.19) X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR11MB0681; X-Microsoft-Antispam-PRVS: X-Forefront-Antispam-Report: BMV:1; SFV:NSPM; SFS:(10009020)(6009001)(24454002)(479174004)(377454003)(36756003)(42186005)(2950100001)(4001350100001)(5001770100001)(65816999)(77156002)(62966003)(99136001)(92566002)(15975445007)(122386002)(86362001)(19580395003)(83506001)(80316001)(87976001)(65956001)(93886004)(46102003)(76176999)(66066001)(40100003)(54356999)(50466002)(50986999)(87266999)(23746002)(64126003)(47776003)(65806001)(33656002)(85282002)(336755003)(18886065003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR11MB0681; H:decina.local; FPR:; SPF:None; MLV:sfv; LANG:en; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(5002010); SRVR:CY1PR11MB0681; BCL:0; PCL:0; RULEID:; SRVR:CY1PR11MB0681; X-Forefront-PRVS: 0555EC8317 X-OriginatorOrg: bluetreble.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Apr 2015 19:49:34.3661 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR11MB0681 X-Pg-Spam-Score: -2.1 (--) 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 4/23/15 5:07 AM, Kyotaro HORIGUCHI wrote: > This is because parsing of UNION immediately converts constants > of unknown type in the UNION's both arms to text so the top level > select won't be bothered by this problem. But the problematic > query doesn't have appropriate timing to do that until the > function I patched. FWIW, I think that's more accidental than anything. I'm no expert in our casting and type handling code but I spent a lot of time stuck in it while working on the variant type, and it seems very scattered. There's stuff in the actual casting code, there's some stuff in other parts of parse/plan, there's stuff in individual types (array and record at least). Some stuff is handled by casting; some stuff is handled by mangling the parse tree. Something else I noticed is we're not consistent with handling typmod either. I don't remember the exact example I found, but there's cases involving casting of constants where we ignore it (I don't think it was as simple as SELECT 1::int::variant(...), but it was something like that). I don't know how much of this is just historical and how much is intentional, but it'd be nice if we could consolidate it more. -- Jim Nasby, Data Architect, Blue Treble Consulting Data in Trouble? Get it in Treble! http://BlueTreble.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers