pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Charles Leifer <coleifer@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Trouble referencing a multi-column unique constraint by name in ON CONFLICT clause
Date: Thu, 27 Sep 2018 14:45:08 -0400
Message-ID: <27450.1538073908@sss.pgh.pa.us> (raw)
In-Reply-To: <CAPukbqwFpGd+Yh_HSXm4mefHNpZ6NfhXk-iLqVvfL3kShPdJuw@mail.gmail.com>
References: <CAPukbqwFpGd+Yh_HSXm4mefHNpZ6NfhXk-iLqVvfL3kShPdJuw@mail.gmail.com>

Charles Leifer <coleifer@gmail.com> 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=# insert into kv (key, value, extra) values ('k1', 'v1', 'e1')
  on conflict (key, value) do update set extra=excluded.extra;
INSERT 0 1
regression=# insert into kv (key, value, extra) values ('k1', 'v1', 'e1')
  on conflict on constraint kv_key_value do update set extra=excluded.extra;
INSERT 0 1

			regards, tom lane




view thread (3+ messages)  latest in thread

Message-ID: <27450.1538073908@sss.pgh.pa.us>
Permalink:  ../27450.1538073908@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/27450.1538073908@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, coleifer@gmail.com
  Subject: Re: Trouble referencing a multi-column unique constraint by name in ON CONFLICT clause
  In-Reply-To: <27450.1538073908@sss.pgh.pa.us>
  References: <CAPukbqwFpGd+Yh_HSXm4mefHNpZ6NfhXk-iLqVvfL3kShPdJuw@mail.gmail.com> <27450.1538073908@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