Merge - Insert Select

Started by Susan Hurstover 8 years ago2 messagesgeneral
Jump to latest
#1Susan Hurst
susan.hurst@brookhurstdata.com

What is the best practice for doing an INSERT...SELECT statement for new
values only. Existing values must be excluded from the insert.

Does postgres have a MERGE statement ala Oracle?

I have found examples online for INSERT...ON CONFLICT DO NOTHING, but
all of those examples use VALUES statements, which is not the scenario
that I have.

Thanks for your help!

Sue

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Susan E Hurst
Principal Consultant
Brookhurst Data LLC
Email: susan.hurst@brookhurstdata.com

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

In reply to: Susan Hurst (#1)
Re: Merge - Insert Select

On Fri, Oct 13, 2017 at 9:39 AM, Susan Hurst
<susan.hurst@brookhurstdata.com> wrote:

Does postgres have a MERGE statement ala Oracle?

No.

I have found examples online for INSERT...ON CONFLICT DO NOTHING, but all of
those examples use VALUES statements, which is not the scenario that I have.

You can use SELECT instead of VALUES with ON CONFLICT DO NOTHING/ON
CONFLICT DO UPDATE. They don't impose any restriction on the INSERT
statement at all, unlike MERGE, which is fussy about the use of
subqueries.

--
Peter Geoghegan

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general