2006-09-03 03:09:23 +02:00
|
|
|
-----------------
|
2006-11-26 16:40:10 +01:00
|
|
|
UPDATE OR INSERT statement
|
2006-09-03 03:09:23 +02:00
|
|
|
-----------------
|
|
|
|
|
|
|
|
Function:
|
2007-05-13 16:06:41 +02:00
|
|
|
Allow to update or insert a record based on the existence (checked with IS NOT DISTINCT) or not of it.
|
2006-09-03 03:09:23 +02:00
|
|
|
|
|
|
|
Author:
|
|
|
|
Adriano dos Santos Fernandes <adrianosf@uol.com.br>
|
|
|
|
|
|
|
|
Syntax rules:
|
2006-11-26 16:40:10 +01:00
|
|
|
UPDATE OR INSERT INTO <table or view> [(<column_list>)]
|
2007-05-11 13:18:40 +02:00
|
|
|
VALUES (<value_list>)
|
2008-07-04 07:05:08 +02:00
|
|
|
[MATCHING (<column_list>)]
|
2007-05-11 13:18:40 +02:00
|
|
|
[RETURNING <column_list> [INTO <variable_list>]]
|
2006-09-03 03:09:23 +02:00
|
|
|
|
|
|
|
Scope:
|
|
|
|
DSQL, PSQL
|
|
|
|
|
|
|
|
Examples:
|
2006-11-26 16:40:10 +01:00
|
|
|
1. UPDATE OR INSERT INTO T1 (F1, F2) VALUES (:F1, :F2);
|
|
|
|
2. UPDATE OR INSERT INTO EMPLOYEE (ID, NAME) VALUES (:ID, :NAME) RETURNING ID;
|
|
|
|
3. UPDATE OR INSERT INTO T1 (F1, F2) VALUES (:F1, :F2) MATCHING (F1);
|
2007-04-24 17:22:05 +02:00
|
|
|
4. UPDATE OR INSERT INTO EMPLOYEE (ID, NAME) VALUES (:ID, :NAME) RETURNING OLD.NAME;
|
2006-09-03 03:09:23 +02:00
|
|
|
|
|
|
|
Notes:
|
2007-05-11 13:18:40 +02:00
|
|
|
1. When MATCHING is omitted, the existence of a primary key is required.
|
|
|
|
2. INSERT and UPDATE permissions are needed on <table or view>.
|
|
|
|
3. If the RETURNING clause is present, then the statement is described as
|
2006-09-03 03:09:23 +02:00
|
|
|
isc_info_sql_stmt_exec_procedure by the API. Otherwise it is described
|
|
|
|
as isc_info_sql_stmt_insert.
|
|
|
|
|
|
|
|
Limitation:
|
|
|
|
1. A singleton error will be raised if the RETURNING clause is present and more than
|
|
|
|
one record match the condition.
|
2010-06-18 14:41:59 +02:00
|
|
|
2. There is no "UPDATE OR INSERT ... SELECT ..." as "INSERT ... SELECT". Use MERGE for
|
|
|
|
this type of functionality.
|