pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tiago Babo <tiago.babo@gmail.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT
Date: Wed, 8 Feb 2017 15:30:38 +0000
Message-ID: <2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com> (raw)
In-Reply-To: <CAH2-Wz=ui3Asb8xtY40L1jF4cxgqmnoSbmpoJT74TWSUYMz69g@mail.gmail.com>
References: <20170202140701.1401.31196@wrigleys.postgresql.org>
	<CAH2-Wz=h4uZuFwAPmU3eNZ-mh=PorhSw75Nt0HYgsWV9GtUMOg@mail.gmail.com>
	<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>
	<CAH2-Wz=J+AtQg5xEm3y6GUO=KfzqsfKy89Vzn0-NayjkF_baVw@mail.gmail.com>
	<CAPsQ5r-2W=cJmJsQfd1qAY=kFuXDnR668iQvL8kTQSCkmoU76w@mail.gmail.com>
	<CAH2-WznXVG2DYXADcr7wXGO+E+YWUrofm4qYat2a-2kbwoD5Xg@mail.gmail.com>
	<D7999A4B-2BF0-4BDD-8C42-09F635897C13@gmail.com>
	<CAH2-WznTcRCcKPNTEduQXz4KLfoWCzAFg3dUBgKQ91LpwxekAQ@mail.gmail.com>
	<31235.1486511840@sss.pgh.pa.us>
	<CAH2-Wzm5RB4H=yiZBJJ5ONQOECb15=KjkS=ZC+r8j56OhTLNhg@mail.gmail.com>
	<CAH2-Wz=ui3Asb8xtY40L1jF4cxgqmnoSbmpoJT74TWSUYMz69g@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Hi, again. After some testing, I was able to reproduce this error with the following code:

CREATE TABLE test (
  type character varying,
  id integer
);

CREATE UNIQUE INDEX uniq_id_test ON test USING btree (type, id) WHERE (type = 'Test');

PREPARE test (text, int, text) AS
  INSERT INTO test (type, id)
  VALUES ($1, $2)
  ON CONFLICT (type, id) WHERE type = $3 DO UPDATE SET id = EXCLUDED.id;


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’);

It gives the error when trying to execute the last statement.

> On 8 Feb 2017, at 01:48, Peter Geoghegan <pg@bowt.ie> wrote:
> 
> On Tue, Feb 7, 2017 at 5:41 PM, Peter Geoghegan <pg@bowt.ie> wrote:
>> It won't work with deferrable constraints (even when immediate
>> enforcement is in effect, so obscure reasons). Enforcement occurs in
>> the executor -- see ExecCheckIndexConstraints().
> 
> Note also that it needs to happen in the executor, because
> infer_arbiter_indexes() may return immediately when ON CONFLICT DO
> NOTHING is used without the user specifying which particular
> constraint to use as an arbiter.  (This is forbidden with ON CONFLICT
> DO UPDATE, since it doesn't make sense to not have an arbiter in mind
> there.)
> 
> This is actually noted directly within infer_arbiter_indexes(), about
> half way down:
> 
> /*
> * Extract info from the relation descriptor for the index.  We know
> * that this is a target, so get lock type it is known will ultimately
> * be required by the executor.
> *
> * Let executor complain about !indimmediate case directly, because
> * enforcement needs to occur there anyway when an inference clause is
> * omitted.
> */
> 
> -- 
> Peter Geoghegan



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (32+ messages)  latest in thread

Message-ID: <2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com>
Permalink:  ../2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com/
Also on:    postgresql.org/message-id/2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tiago.babo@gmail.com, pg@bowt.ie, tgl@sss.pgh.pa.us
  Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT
  In-Reply-To: <2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com>
  References: <20170202140701.1401.31196@wrigleys.postgresql.org> <CAH2-Wz=h4uZuFwAPmU3eNZ-mh=PorhSw75Nt0HYgsWV9GtUMOg@mail.gmail.com> <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> <CAH2-Wz=J+AtQg5xEm3y6GUO=KfzqsfKy89Vzn0-NayjkF_baVw@mail.gmail.com> <CAPsQ5r-2W=cJmJsQfd1qAY=kFuXDnR668iQvL8kTQSCkmoU76w@mail.gmail.com> <CAH2-WznXVG2DYXADcr7wXGO+E+YWUrofm4qYat2a-2kbwoD5Xg@mail.gmail.com> <D7999A4B-2BF0-4BDD-8C42-09F635897C13@gmail.com> <CAH2-WznTcRCcKPNTEduQXz4KLfoWCzAFg3dUBgKQ91LpwxekAQ@mail.gmail.com> <31235.1486511840@sss.pgh.pa.us> <CAH2-Wzm5RB4H=yiZBJJ5ONQOECb15=KjkS=ZC+r8j56OhTLNhg@mail.gmail.com> <CAH2-Wz=ui3Asb8xtY40L1jF4cxgqmnoSbmpoJT74TWSUYMz69g@mail.gmail.com> <2205EBF5-5095-4389-9D6B-1469EE60A0AD@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox