Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbAuT-0001BI-5P for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 18:54:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cbAuS-0000o7-Ou for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 18:54:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cbAuS-0000nk-3n for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 18:54:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cbAuP-0000g4-Ik for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 18:54:34 +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 v17IsVmu014576; Tue, 7 Feb 2017 13:54:31 -0500 From: Tom Lane To: Tiago Babo cc: Peter Geoghegan , pgsql-bugs@postgresql.org Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT In-reply-to: <166D0A9D-162D-4216-9490-3163533166C1@gmail.com> References: <20170202140701.1401.31196@wrigleys.postgresql.org> <166D0A9D-162D-4216-9490-3163533166C1@gmail.com> Comments: In-reply-to Tiago Babo message dated "Tue, 07 Feb 2017 17:25:43 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14574.1486493671.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 07 Feb 2017 13:54:31 -0500 Message-ID: <14575.1486493671@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 Tiago Babo writes: > Indexes: > "accounts_pkey" PRIMARY KEY, btree (id) > "index_accounts_on_type_and_identifier" UNIQUE, btree (type, identifie= r) > "uniq_bank_accounts" UNIQUE, btree (type, identifier) WHERE type::text= =3D 'BankAccount'::text > "uniq_business_accounts" UNIQUE, btree (type, business_id) WHERE type:= :text =3D 'BusinessAccount'::text > "uniq_person_accounts" UNIQUE, btree (person_id) WHERE type::text =3D = '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 --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs