Subject Re: [Firebird-Architect] REPLACE statement
Author Jim Starkey
Dmitry Yemanov wrote:

>"Adriano dos Santos Fernandes" <adrianosf@...> wrote:
>
>
>>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.
>>
>>
>
>Correct. I don't like it much either :-) But it provides more flexibility.
>Imagine that you need to either increment values for an existing record or
>add a new record with the base values.
>
>Could we consider implementation of the SQL-compliant MERGE and then add
>REPLACE (or just a more user-friendly syntax of MERGE) as a shortcut for the
>simplified semantics? I mean to implement them both using a single BLR verb.
>
>
>
>>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;
>>
>>
>
>
>
I've had replace in Netfrastructure from the beginning. It saves a
great amount of really boring application code. I used the syntax
parallel to insert to take advantage of "replace ... select", which
although rare, is useful.

I didn't implement the form without without an explicit field list
becauseI believe that nobody but a fool would rely on table field order
for an update statement. If you think that we have fools among our
users, maybe we should implement it to keep them happy.

So

REPLACE INTO <table> ( <field list> ) VALUES ( <value list> )

and

REPLACE INTO <table> ( <field list> ) <select statement>


For more gory details, see
http://www/docs/home.nfs?a=docs&l=;TOPICS;NAME='replace'