From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tiago Babo <tiago.babo@gmail.com>
Cc: Peter Geoghegan <pg@bowt.ie>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT
Date: Tue, 07 Feb 2017 13:54:31 -0500
Message-ID: <14575.1486493671@sss.pgh.pa.us> (raw)
In-Reply-To: <166D0A9D-162D-4216-9490-3163533166C1@gmail.com>
References: <20170202140701.1401.31196@wrigleys.postgresql.org>
<CAH2-Wz=h4uZuFwAPmU3eNZ-mh=PorhSw75Nt0HYgsWV9GtUMOg@mail.gmail.com>
<166D0A9D-162D-4216-9490-3163533166C1@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Tiago Babo <tiago.babo@gmail.com> writes:
> Indexes:
> "accounts_pkey" PRIMARY KEY, btree (id)
> "index_accounts_on_type_and_identifier" UNIQUE, btree (type, identifier)
> "uniq_bank_accounts" UNIQUE, btree (type, identifier) WHERE type::text = 'BankAccount'::text
> "uniq_business_accounts" UNIQUE, btree (type, business_id) WHERE type::text = 'BusinessAccount'::text
> "uniq_person_accounts" UNIQUE, btree (person_id) WHERE type::text = 'PersonAccount'::text
> "index_accounts_on_business_id" btree (business_id)
> "index_accounts_on_person_id" btree (person_id)
So according to that, you *don't* have a unique index over (type, person_id).
(A sufficiently clever person might realize that the partial index on
person_id would serve in this instance, but I do not expect that Postgres
would figure that out.)
That makes the question less about why it fails and more about why it
seems to sometimes work. It shouldn't, at least not with this set of
indexes and this query.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: tgl@sss.pgh.pa.us, tiago.babo@gmail.com, pg@bowt.ie
Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT
In-Reply-To: <14575.1486493671@sss.pgh.pa.us>
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>
* 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