Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5bHs-0007wZ-9E for pgsql-general@arkaria.postgresql.org; Thu, 27 Sep 2018 18:45:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5bHq-0001oE-Ln for pgsql-general@arkaria.postgresql.org; Thu, 27 Sep 2018 18:45:18 +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.89) (envelope-from ) id 1g5bHq-0001o7-Dk for pgsql-general@lists.postgresql.org; Thu, 27 Sep 2018 18:45:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5bHk-00058X-Pp for pgsql-general@postgresql.org; Thu, 27 Sep 2018 18:45:18 +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 w8RIj8ve027451; Thu, 27 Sep 2018 14:45:08 -0400 From: Tom Lane To: Charles Leifer cc: pgsql-general@postgresql.org Subject: Re: Trouble referencing a multi-column unique constraint by name in ON CONFLICT clause In-reply-to: References: Comments: In-reply-to Charles Leifer message dated "Thu, 27 Sep 2018 13:30:10 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27449.1538073908.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 27 Sep 2018 14:45:08 -0400 Message-ID: <27450.1538073908@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Charles Leifer writes: > I'm running into behavior I don't understand when trying to do an UPSERT > with Postgres. The docs would seem to indicate that the conflict target = of > the INSERT statement can be either an index expression or a constraint > name. However, when attempting to reference the constraint name, I get a > "column ... does not exist" error. What I see in the INSERT reference page is where conflict_target can be one of: ( { index_column_name | ( index_expression ) } [ COLLATE collation ] [= opclass ] [, ...] ) [ WHERE index_predicate ] ON CONSTRAINT constraint_name So you can write a parenthesized list of column names, or you can write "ON CONSTRAINT constraint_name". Given your second example with create table kv ( key text, value text, extra text, constraint kv_key_value unique(key, value)); either of these work for me: regression=3D# insert into kv (key, value, extra) values ('k1', 'v1', 'e1'= ) on conflict (key, value) do update set extra=3Dexcluded.extra; INSERT 0 1 regression=3D# insert into kv (key, value, extra) values ('k1', 'v1', 'e1'= ) on conflict on constraint kv_key_value do update set extra=3Dexcluded.ex= tra; INSERT 0 1 regards, tom lane