Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbWRB-0001yp-NI for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Feb 2017 17:53:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cbWRB-0001Ni-A4 for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Feb 2017 17:53:49 +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.84_2) (envelope-from ) id 1cbW0l-0004AL-V0 for pgsql-bugs@postgresql.org; Wed, 08 Feb 2017 17:26:32 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cbW0i-00026G-Ba for pgsql-bugs@postgresql.org; Wed, 08 Feb 2017 17:26:31 +0000 Received: by mail-wm0-x244.google.com with SMTP id c85so34354363wmi.1 for ; Wed, 08 Feb 2017 09:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=gW1sLXdMmnVG1tqEHfkdBCUeLx0Qx/P7y6O0EebHKw0=; b=e08w8L12es5tmvGBzJ29+NvxYHMV3Su5+N/89EtitiXAUUqnYvxa5efHAlayW/+ZYw nnxGQpTYBjLe/XejJGoVNT6uVpozzsYHt1kHhkakN99F43HjaBTIhDQYsjo7zlXd8MAZ Wd85GCG8nTFtWFf83DfLbR50NAFFdsUTML7WZ52cMjKk3IJTL/8gwmlEXodlwFMC6zE1 DW7L3kFHq4yy56m+s0sHW/U22Cw6UPC6tmPOxs1MWzM02ppy48opb5fXRSA04G5S6dWj 0HyvhbHUshNc8YF85p9UGFvQJCNXEONXDNonROwrwKkqEIDrmyIMOwrC4aQYCn2/XAFK Fi/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=gW1sLXdMmnVG1tqEHfkdBCUeLx0Qx/P7y6O0EebHKw0=; b=dZ2agVK1c3//bRUm9oZTYEAGye5UAqDYQ0tHHJE51FuyTCAmJw3j+64K+IsUuqeR7g Afoi9VJGFA5Bwz/cAx376rXfqkRnl1BfzfKU/E0t9JxcKvptexFyAKydMmGunTaQPYtw ztZ8gK6peNxN2Ovx5IriRw7GH4ED42pOUwBPVxbzStLs9WpfISJNlJXceSyeGWVnTmC9 iWR9ogmWyS18xE2eaMRzXWXFcY2b7pQt4qCGNkrAxcqAxg5Fhl1blaCZ1RhEKnN7VQmn ElAtgd6Do1XV9aw05mq1kMVi14CLmBhcLrGLvyS2YvPcClxNQAGUhIAu3KjtWMeLFH7T cAxw== X-Gm-Message-State: AMke39mhTqlxV3q8ejIIIGSLJXgYmbMgY4HRWSyIkg3OUEwkm1uWlLSujWpqML021ypiPQ== X-Received: by 10.28.184.133 with SMTP id i127mr17390245wmf.49.1486574786342; Wed, 08 Feb 2017 09:26:26 -0800 (PST) Received: from [192.168.0.100] (a109-51-13-153.cpe.netcabo.pt. [109.51.13.153]) by smtp.gmail.com with ESMTPSA id h3sm14131245wrb.31.2017.02.08.09.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 09:26:25 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (1.0) Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT From: Tiago Babo X-Mailer: iPhone Mail (14D27) In-Reply-To: <4487.1486573790@sss.pgh.pa.us> Date: Wed, 8 Feb 2017 17:26:24 +0000 Cc: Peter Geoghegan , pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <176C4C3F-A4A8-49AE-BEE0-2CF28A113FB5@gmail.com> References: <20170202140701.1401.31196@wrigleys.postgresql.org> <166D0A9D-162D-4216-9490-3163533166C1@gmail.com> <14575.1486493671@sss.pgh.pa.us> <499844AD-291B-40F5-9892-E5591736FD2E@gmail.com> <22106.1486500247@sss.pgh.pa.us> <31235.1486511840@sss.pgh.pa.us> <2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com> <4487.1486573790@sss.pgh.pa.us> To: Tom Lane X-Pg-Spam-Score: -2.7 (--) 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 This is not how my application is doing the insert (like I showed you befor= e), but it was the only way I could continuously get the error. I'm using a= Scala library called ScalikeJDBC to access the database. So maybe the prob= lem is on how it handles the execution.=20 > On 8 Feb 2017, at 17:09, Tom Lane wrote: >=20 > Tiago Babo writes: >> Hi, again. After some testing, I was able to reproduce this error with t= he following code: >=20 >> CREATE UNIQUE INDEX uniq_id_test ON test USING btree (type, id) WHERE (t= ype =3D 'Test'); >=20 >> PREPARE test (text, int, text) AS >> INSERT INTO test (type, id) >> VALUES ($1, $2) >> ON CONFLICT (type, id) WHERE type =3D $3 DO UPDATE SET id =3D EXCLUDED.= id; >=20 >> EXECUTE test('Test', 1, 'Test'); >> EXECUTE test('Test', 2, 'Test'); >> EXECUTE test('Test', 3, 'Test'); >> EXECUTE test('Test', 4, 'Test'); >> EXECUTE test('Test', 5, 'Test'); >> EXECUTE test('Test', 6, 'Test'); >=20 >> It gives the error when trying to execute the last statement. >=20 > Hm. So the problem here is that the prepared statement only matches the > partial index as long as the actual parameter is substituted literally > into the statement. As soon as the plancache tries to consider a generic > plan, in which it's not apparent at plan time what $3 is, we can't prove > the partial index to be matched so you get the error. >=20 > If this is representative of what your application is actually doing, > rather than what you were saying it does, then the answer is that you > have to match the partial index clause exactly, not rely on substitution/ > simplification to produce a match. >=20 > Or don't use a partial index. That schema seems pretty bizarre to me > anyway. >=20 > Having said all that, I think this is a fine example of why relying on > planner inferences for semantic decisions (rather than just optimization) > is damn-fool design. If I'd been paying closer attention I would have > objected loudly to the use of WHERE in ON CONFLICT for this purpose. > I wonder whether it's too late to deprecate that feature. >=20 > regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs