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:
Example
update or insert into Cows (Name, Number, Location) values ('Suzie Moo', 3278823, 'Green Pastures') matching (Number) returning rec_id into :id;
Notes: