Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbBjp-0003UX-1Q for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 19:47:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cbBjo-0008BQ-Kn for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Feb 2017 19:47:40 +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 1cbBWg-0005Z3-6k for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 19:34:06 +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 1cbBWc-00022n-Sy for pgsql-bugs@postgresql.org; Tue, 07 Feb 2017 19:34:05 +0000 Received: by mail-wm0-x244.google.com with SMTP id v77so30106671wmv.0 for ; Tue, 07 Feb 2017 11:34:02 -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=jqFlKEHDHfac85sqQKjrqBsrzW0bioEl6pFZyl3Qlec=; b=YBdn1z+nHPdV9upEsDYHft3Gp0zbfxGmXTfF/qWntMLjX5eDGtS8UDxtV0ZaM+mrj2 N7worM4BKMxVabiz1YTzMU0NHNztQx4U/8W774QfvH8UOXHPL0SR2JsaOlZJUaJATAs2 gSXpN9I1ozUA+qh/wiWLWUMr0FnghVP/vme98ojQVYKQ881+EKqTAEfTG79jNJQJsMdv gIE2tbB7CXe61tdZFDZtaw9E9Mv6mpXXs4bS3LLAhwBVAmOnHG5Hc+ji9qfUzDJkAqcm hiqgTg2WLoLL3y1NMpyCwHibgm8/mqsUNwUo5kcPfbbH580Cd3NvJFazt/BCGdIj22d7 DODA== 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=jqFlKEHDHfac85sqQKjrqBsrzW0bioEl6pFZyl3Qlec=; b=d3xHkGU1uzJvlElgxrF7RT+Iw0KcmRLW6u/oqvpvQA7xhVpgFc2DjziArD2KOuDz9W LypfFQpWFmfRfy1ELygG7WAI8G0TrNpU4Cd3d8Ctdp3lAO5O7y7H+LWLwy9dKLQ0aXLQ 5ByrSLd7CaYsVW3MIiCFTGwF0U0YfEjnUiOSTs47c08S2hqo5EAJGZI+Ie3nrPO7J7tS yyLeIEJst7ZeJaZhQIf3G0KqedqnZEUqnVndD8LOQVke8nZqwxp8t9u7upzJBbfHWtQx N3MKy1U3V5vuXjeEG0RWse05t/VAddAjAyd8Wo/sciKNYqVVtH3CBVA7zeferVtWb3fD AitQ== X-Gm-Message-State: AIkVDXIvk0bXmqR52bVU+gLs4Jm2nESSzHUaLmhCLVqxKZTLtl4s76U3OtXYpS/m4qMXpA== X-Received: by 10.223.176.210 with SMTP id j18mr18352554wra.8.1486496040932; Tue, 07 Feb 2017 11:34:00 -0800 (PST) Received: from [192.168.0.103] (a109-51-13-153.cpe.netcabo.pt. [109.51.13.153]) by smtp.gmail.com with ESMTPSA id r19sm4003927wrr.44.2017.02.07.11.33.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 11:34:00 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Subject: Re: BUG #14526: no unique or exclusion constraint matching the ON CONFLICT From: Tiago Babo In-Reply-To: <14575.1486493671@sss.pgh.pa.us> Date: Tue, 7 Feb 2017 19:33:59 +0000 Cc: Peter Geoghegan , pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <499844AD-291B-40F5-9892-E5591736FD2E@gmail.com> References: <20170202140701.1401.31196@wrigleys.postgresql.org> <166D0A9D-162D-4216-9490-3163533166C1@gmail.com> <14575.1486493671@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3259) 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 Ups, I used the wrong database. I was experimenting with it a bit and didn= =E2=80=99t noticed I was copying from the wrong one. Where is the correct v= ersion (and the one that is giving me those =E2=80=9Crandom=E2=80=9D errors= ): Column | Type | = Modifiers | Storage | Stats target | De= scription ----------------------------------+-----------------------------+----------= ---------------------------------------------+----------+--------------+---= ---------- id | integer | not null = default nextval('accounts_id_seq'::regclass) | plain | | type | character varying | = | extended | | identifier | character varying | = | extended | | person_id | integer | = | plain | | business_id | integer | = | plain | | 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 = =3D 'BankAccount'::text "uniq_business_accounts" UNIQUE, btree (type, business_id) WHERE type::= text =3D 'BusinessAccount'::text "uniq_person_accounts" UNIQUE, btree (type, person_id) WHERE type::text= =3D 'PersonAccount'::text "index_accounts_on_business_id" btree (business_id) "index_accounts_on_person_id" btree (person_id) Foreign-key constraints: "fk_rails_156241f05a" FOREIGN KEY (business_id) REFERENCES businesses(i= d) "fk_rails_777d10a224" FOREIGN KEY (person_id) REFERENCES persons(id) > On 7 Feb 2017, at 18:54, Tom Lane wrote: >=20 > 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) >=20 > 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.) >=20 > 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. >=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