Subject | REPLACE statement |
---|---|
Author | Adriano dos Santos Fernandes |
Post date | 2006-02-10T13:54:52Z |
Hi!
SQL standard has MERGE statement, used to insert a row when a condition
is false or update when the condition is true.
MERGE is not very user friendly.
It's like a INSERT and UPDATE mixed in one statement. You should pass
the parameters twice.
I would like to implement non-standard (google says that MySQL has it
and AFAIR Netfrastructure has it too :-)) REPLACE statement.
Syntax of REPLACE can be one of these:
REPLACE INTO table_name [(column [, column ...])] VALUES (value [,
value ...])
replace into table (pk, x) values (1, 11);
replace into table (values (1, 11);
or
REPLACE table_name SET column = value [, column = value ...]
replace table set pk = 1, x = 11;
REPLACE needs that the table has a PK and that all fields of the PK has
in the statement.
Could we store a dependency of a SP on a constraint name for this
condition don't break or we do this verification before execute REPLACE
(maybe in CMP?)?
If the first, I think it can be implemented without new BLR verb
(although I don't think that will be good). If the second, a new BLR
verb is required.
Comments?
Adriano
SQL standard has MERGE statement, used to insert a row when a condition
is false or update when the condition is true.
MERGE is not very user friendly.
It's like a INSERT and UPDATE mixed in one statement. You should pass
the parameters twice.
I would like to implement non-standard (google says that MySQL has it
and AFAIR Netfrastructure has it too :-)) REPLACE statement.
Syntax of REPLACE can be one of these:
REPLACE INTO table_name [(column [, column ...])] VALUES (value [,
value ...])
replace into table (pk, x) values (1, 11);
replace into table (values (1, 11);
or
REPLACE table_name SET column = value [, column = value ...]
replace table set pk = 1, x = 11;
REPLACE needs that the table has a PK and that all fields of the PK has
in the statement.
Could we store a dependency of a SP on a constraint name for this
condition don't break or we do this verification before execute REPLACE
(maybe in CMP?)?
If the first, I think it can be implemented without new BLR verb
(although I don't think that will be good). If the second, a new BLR
verb is required.
Comments?
Adriano