UPDATE OR INSERT | sql insert or update
UPDATEORINSERTAvailablein: DSQL,PSQLAddedin: 2.1Description: UPDATEORINSERTchecksifanyexistingrecordsalreadycontainthenewvaluessuppliedfortheMATCHINGcolumns.Ifso,thoserecordsareupdated.Ifnot,anewrecordisinserted.IntheabsenceofaMATCHINGclause,matchingisdoneagainsttheprimarykey.IfaRETURNINGclauseispresentandmorethanonematchingrecordisfound,anerrorisraised.Syntax: UPDATEORINSERTINTO{tablename|viewname}[(
Available in: DSQL, PSQL
Added in: 2.1
Description: UPDATE OR INSERT checks if any existing records already contain the new values supplied for the MATCHING columns. If so, those records are updated. If not, a new record is inserted. In the absence of a MATCHING clause, matching is done against the primary key. If a RETURNING clause is present and more than one matching record is found, an error is raised.
Syntax:
UPDATE OR INSERT INTO {tablename | viewname} [(<columns>)] VALUES (<values>) [MATCHING (<columns>)] [RETURNING <values> [INTO <variables>]] <columns> ::= colname [, colname ...] <values> ::= value [, value ...] <variables> ::= :varname [, :varname ...] Restrictions ...