Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fW321-0003dO-OF for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Jun 2018 17:06:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fW320-0007H4-8q for pgsql-bugs@arkaria.postgresql.org; Thu, 21 Jun 2018 17:06:00 +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.89) (envelope-from ) id 1fW320-0007Gw-34 for pgsql-bugs@lists.postgresql.org; Thu, 21 Jun 2018 17:06:00 +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.89) (envelope-from ) id 1fW31w-0006Ob-Rb for pgsql-bugs@lists.postgresql.org; Thu, 21 Jun 2018 17:05:59 +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 w5LH5rPn018796; Thu, 21 Jun 2018 13:05:54 -0400 From: Tom Lane To: Mario De Frutos Dieguez cc: pgsql-bugs@lists.postgresql.org Subject: Re: Fwd: Problem with a "complex" upsert In-reply-to: References: Comments: In-reply-to Mario De Frutos Dieguez message dated "Thu, 21 Jun 2018 16:11:09 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <18657.1529600576.0@sss.pgh.pa.us> Date: Thu, 21 Jun 2018 13:05:53 -0400 Message-ID: <18795.1529600753@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18657.1529600576.1@sss.pgh.pa.us> Mario De Frutos Dieguez writes: > I'm trying to do an upsert to an updatable view with the following SQL > query: > ... > If I don't get any conflict everything works as intended but if we hit a > conflict then I get the following error message: > ERROR: attribute 2 of type record has the wrong type > DETAIL: Table has type character varying, but query expects double > precision. When filing a bug report, it's a good idea to provide both a self- contained test case and a mention of what PG version you're using. I guess from the ROW() syntax you used here, which isn't accepted pre-v10, that you're using 10.0 or later, but that's not specific enough. I tried to duplicate this problem using the attached script, but it works for me. FWIW, that error message definitely looks like a bug, but I can't tell whether it's an already-fixed bug or there's some triggering detail you didn't mention. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/plain; name="this-test-case-doesnt-fail.sql"; charset="us-ascii" Content-ID: <18657.1529600576.2@sss.pgh.pa.us> Content-Description: this-test-case-doesnt-fail.sql drop schema if exists tiger2015 cascade; drop schema if exists acs2014_5yr cascade; create schema tiger2015; create table tiger2015.blocks_interpolation ( blockid text, blockgroupid text, percentage float8 ); create schema acs2014_5yr; create table acs2014_5yr.seq0003 ( geoid character varying(40) primary key, b01003001 double precision ); insert into acs2014_5yr.seq0003 values ('15000US020200001013', 42); insert into tiger2015.blocks_interpolation values ('020200001013', '020200001013', 99); create view acs2014_5yr.b01003 as SELECT seq0003.geoid, seq0003.b01003001 FROM acs2014_5yr.seq0003; INSERT INTO "acs2014_5yr"."b01003" (geoid, b01003001) SELECT (left(acs.geoid, 7) || bi.blockid) geoid, (b01003001 * (percentage*100.0)) b01003001 FROM "tiger2015".blocks_interpolation bi INNER JOIN "acs2014_5yr"."b01003" acs ON bi.blockgroupid = substr(acs.geoid,8) WHERE acs.geoid = '15000US020200001013' AND char_length(substr(acs.geoid, 8)) = 12 ON CONFLICT (geoid) DO UPDATE SET (b01003001) = ROW(EXCLUDED.b01003001); ------- =_aaaaaaaaaa0--