postgresql/src/backend/commands
Andres Freund 168d5805e4 Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE.
The newly added ON CONFLICT clause allows to specify an alternative to
raising a unique or exclusion constraint violation error when inserting.
ON CONFLICT refers to constraints that can either be specified using a
inference clause (by specifying the columns of a unique constraint) or
by naming a unique or exclusion constraint.  DO NOTHING avoids the
constraint violation, without touching the pre-existing row.  DO UPDATE
SET ... [WHERE ...] updates the pre-existing tuple, and has access to
both the tuple proposed for insertion and the existing tuple; the
optional WHERE clause can be used to prevent an update from being
executed.  The UPDATE SET and WHERE clauses have access to the tuple
proposed for insertion using the "magic" EXCLUDED alias, and to the
pre-existing tuple using the table name or its alias.

This feature is often referred to as upsert.

This is implemented using a new infrastructure called "speculative
insertion". It is an optimistic variant of regular insertion that first
does a pre-check for existing tuples and then attempts an insert.  If a
violating tuple was inserted concurrently, the speculatively inserted
tuple is deleted and a new attempt is made.  If the pre-check finds a
matching tuple the alternative DO NOTHING or DO UPDATE action is taken.
If the insertion succeeds without detecting a conflict, the tuple is
deemed inserted.

To handle the possible ambiguity between the excluded alias and a table
named excluded, and for convenience with long relation names, INSERT
INTO now can alias its target table.

Bumps catversion as stored rules change.

Author: Peter Geoghegan, with significant contributions from Heikki
    Linnakangas and Andres Freund. Testing infrastructure by Jeff Janes.
Reviewed-By: Heikki Linnakangas, Andres Freund, Robert Haas, Simon Riggs,
    Dean Rasheed, Stephen Frost and many others.
2015-05-08 05:43:10 +02:00
..
aggregatecmds.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
alter.c Remove variable shadowing 2015-04-07 17:14:00 -03:00
analyze.c Add log_min_autovacuum_duration per-table option 2015-04-03 11:55:50 -03:00
async.c Use FLEXIBLE_ARRAY_MEMBER in a number of other places. 2015-02-21 16:12:14 -05:00
cluster.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
collationcmds.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
comment.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
constraint.c Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. 2015-05-08 05:43:10 +02:00
conversioncmds.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
copy.c Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. 2015-05-08 05:43:10 +02:00
createas.c Represent columns requiring insert and update privileges indentently. 2015-05-08 00:20:46 +02:00
dbcommands.c Move WAL-related definitions from dbcommands.h to separate header file. 2015-03-09 15:50:49 +02:00
define.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
discard.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
dropcmds.c Add transforms feature 2015-04-26 10:33:14 -04:00
event_trigger.c Add transforms feature 2015-04-26 10:33:14 -04:00
explain.c Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. 2015-05-08 05:43:10 +02:00
extension.c Allow CURRENT/SESSION_USER to be used in certain commands 2015-03-09 15:41:54 -03:00
foreigncmds.c Allow CURRENT/SESSION_USER to be used in certain commands 2015-03-09 15:41:54 -03:00
functioncmds.c Add transforms feature 2015-04-26 10:33:14 -04:00
indexcmds.c Fix various typos and grammar errors in comments. 2015-04-26 18:42:31 +02:00
lockcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
matview.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
opclasscmds.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
operatorcmds.c Allow named parameters to be specified using => in addition to := 2015-03-10 11:09:41 -04:00
policy.c Allow CURRENT/SESSION_USER to be used in certain commands 2015-03-09 15:41:54 -03:00
portalcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
prepare.c Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
proclang.c Add transforms feature 2015-04-26 10:33:14 -04:00
schemacmds.c Allow CURRENT/SESSION_USER to be used in certain commands 2015-03-09 15:41:54 -03:00
seclabel.c Change many routines to return ObjectAddress rather than OID 2015-03-03 14:10:50 -03:00
sequence.c Create an infrastructure for parallel computation in PostgreSQL. 2015-04-30 15:02:14 -04:00
tablecmds.c Fix overlooked relcache invalidation in ALTER TABLE ... ALTER CONSTRAINT. 2015-05-03 11:30:24 -04:00
tablespace.c Warn about tablespace creation in PGDATA 2015-04-28 17:35:12 -04:00
trigger.c Add support for INSERT ... ON CONFLICT DO NOTHING/UPDATE. 2015-05-08 05:43:10 +02:00
tsearchcmds.c Add OID output argument to DefineTSConfiguration 2015-03-25 15:57:08 -03:00
typecmds.c Add transforms feature 2015-04-26 10:33:14 -04:00
user.c Integrate pg_upgrade_support module into backend 2015-04-14 19:26:37 -04:00
vacuum.c Add log_min_autovacuum_duration per-table option 2015-04-03 11:55:50 -03:00
vacuumlazy.c Add log_min_autovacuum_duration per-table option 2015-04-03 11:55:50 -03:00
variable.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
view.c Require non-NULL pstate for all addRangeTableEntryFor* functions. 2015-03-11 15:26:43 -04:00