Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YnqzU-0003O4-1T for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Apr 2015 16:07:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YnqzS-0005NR-Sb for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Apr 2015 16:07:06 +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 1YnqzR-0005LW-Fp for pgsql-bugs@postgresql.org; Thu, 30 Apr 2015 16:07:06 +0000 Received: from nm17-vm3.bullet.mail.ne1.yahoo.com ([98.138.91.147]) by makus.postgresql.org with esmtps (TLS1.0:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1YnqzO-00026n-HF for pgsql-bugs@postgresql.org; Thu, 30 Apr 2015 16:07:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s2048; t=1430410020; bh=Z9ZyTkIzzVMJmuVchdWTtWY2O+bM464RwXkbukhWMVo=; h=Date:From:Reply-To:To:Cc:In-Reply-To:References:Subject:From:Subject; b=rBuzVzf+enCB74jf2rsadFZDkfssbLjlgxXsGEzBQHr0ut8WDEaV5qamKQwboOONeZ9Fe5BallJqGdN+k4PhEOsLyNX09jVtyd1yvW2xNfIuA1s7cyCUmd1w4dgSpAqYJjHvCh3VeU2m7KYHh3zDXmYs5pXx5XcOO+LbRV5sROi4C4JnJXGbepaBEmLpgqVjFg+vGu+JF9+SslrPR74AucDApWGq/o2cGYMV2sioQkGxFABhJsnhw4B1Kess92vzVDnU65oUv2wYTSCf51KDy00en0B2GyYQ5GtUriADuEhB8ueCf+DzUldURqPEdipI31DqK0AuaeetfIBoMBjy7w== Received: from [98.138.226.177] by nm17.bullet.mail.ne1.yahoo.com with NNFMP; 30 Apr 2015 16:07:00 -0000 Received: from [98.138.89.253] by tm12.bullet.mail.ne1.yahoo.com with NNFMP; 30 Apr 2015 16:07:00 -0000 Received: from [127.0.0.1] by omp1045.mail.ne1.yahoo.com with NNFMP; 30 Apr 2015 16:07:00 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 350111.11278.bm@omp1045.mail.ne1.yahoo.com X-YMail-OSG: lGwen5QVM1muoqAYESY3iMN_EoHP_fD.XGFpEfyFVBLebeWw1af5Q5_FLyRo851 lwny2TH_yOUfBxNipj3.._94Bwkqsr1xSS7vSzQsa3787eD9G7S1tDBTsMnGHQIRq_aHgytyp_z. y2pZQC8z4mVIXP_KV1DfrRzvj8gd25gkwv3BvD9DFubb88k0L2VR8JuVvP7CMgtBuvTceB.2DGUx _REmOhkILIo1H9aVoJuIJutbOcQdiE6IqBRtd4gxTHM3ifVyyqc90yCGgFsSsRici8dgIYIodOvX uGDC4PERufvRUyPUGJPfQHJu1rYhpf.mXalevOTK_opfzWh9g7shAYZkLVB8AP8uZVNHddTNNlhJ VgSfO60tB1aPAOMblyADfZLuDX4_zZ0PXh28tLcoThzBYn.Sh0eW8KF_0W7.chsqkm80rJe8L6lO DOpEriO8TZIfvZXsn5ICXcVyABAWs8cWOyMnIesTdw1pO8x2kdesEKqh3KB7fohTTWcebgU48YFy qSjkIUKUT.zbmN5EflSpAeDu2bqkSwBqF.MpZ7.hY5zRsDJi9.w.Nke_s Received: by 98.138.105.192; Thu, 30 Apr 2015 16:06:59 +0000 Date: Thu, 30 Apr 2015 16:06:45 +0000 (UTC) From: Kevin Grittner Reply-To: Kevin Grittner To: Tom Lane , Robert Haas Cc: Jeff Davis , Postgres-Bugs Message-ID: <1439794807.1364461.1430410005618.JavaMail.yahoo@mail.yahoo.com> In-Reply-To: <35651.1430347071@sss.pgh.pa.us> References: <35651.1430347071@sss.pgh.pa.us> Subject: Re: Failure to coerce unknown type to specific type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 1997 X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Tom Lane wrote: > I have some recollection that we'd also put it off pending > resolution of debates about how to handle unknown-type literals > in UNIONs and similar contexts. But poking at such examples > right now, the behavior seems generally reasonable: it seems like > we resolve "unknown" as text when forced to make a decision, but > otherwise put it off as long as possible. So that consideration > may be obsolete. I recall two constructs that we had in production that caused some pain moving to PostgreSQL. Here's one: test=# create table x (d date); CREATE TABLE test=# insert into x values (null); INSERT 0 1 test=# insert into x values (coalesce(null, null)); ERROR: column "d" is of type date but expression is of type text LINE 1: insert into x values (coalesce(null, null)); ^ HINT: You will need to rewrite or cast the expression. I know these worked in Sybase ASE, SAP DB, MySQL MaxdDB, IBM OS/2 EE's port of DB2, and early versions of MS SQL Server. I have confirmed (using SQL Fiddle) that it works in Oracle 11g R2, MySQL 5.5 and 5.6, and SQLite (SQL.js). Interestingly, MS SQL Server 2014 now throws this error: At least one of the arguments to COALESCE must be an expression that is not the NULL constant. Here the other: test=# select null as ts union all select null union all select now(); ERROR: UNION types text and timestamp with time zone cannot be matched LINE 1: ...ect null as ts union all select null union all select now(); ^ test=# create table n (id int not null); CREATE TABLE test=# insert into n values (1); INSERT 0 1 test=# select null as ts from n test-# union all test-# select null from n test-# union all test-# select 1 from n; ERROR: UNION types text and integer cannot be matched LINE 5: select 1 from n; ^ This runs in *all* of the above environments. I don't know of any other database product which chokes on the above. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs