Returning Values from INSERT ON CONFLICT DO NOTHING - Mailing list pgsql-general

From Igal Sapir
Subject Returning Values from INSERT ON CONFLICT DO NOTHING
Date
Msg-id CA+zig0_Joi5+toujDMF0K80x6kLaXJuHDk0kmDRNkiK5oW-jpQ@mail.gmail.com
Whole thread Raw
Responses Re: Returning Values from INSERT ON CONFLICT DO NOTHING  (Igal Sapir <igal@lucee.org>)
List pgsql-general
Hello,

I want to use the "UPSERT" syntax for returning an ID if it exists, or inserting a record and returning the new ID if it does not exist.

INSERT INTO users(email, name)
  VALUES('user@domain.tld', 'User')
  ON CONFLICT (email) DO NOTHING
  RETURNING user_id, (xmax::text::int > 0) as existed;

When an email address does not exist then it works fine and I get the new user_id, but when it does exist, I get no results at all.

How can I get the results in case of a CONFLICT?

Thanks,


Igal

pgsql-general by date:

Previous
From: Paul Jungwirth
Date:
Subject: Re: Use of Port 5433 with Postgresql 9.6
Next
From: Igal Sapir
Date:
Subject: Re: Returning Values from INSERT ON CONFLICT DO NOTHING