Subject | RE: [firebird-support] Correct use of "UPDATE OR INSERT...." |
---|---|
Author | Sasha Matijasic |
Post date | 2008-01-31T22:50:13Z |
>Which is exactly as documented. You can try something like this:
> UPDATE OR INSERT INTO MYTABLE (MY_ID, NAME, MY_QTY) VALUES ( 1 ,
> 'Something', 7)
>
> The last statement update the record 1 and changes 10 with 7.
>
> How i can perform an arithmetic operation with these values and, por
> example, add 10 + 7?
>
UPDATE OR INSERT INTO MYTABLE (MY_ID, NAME, MY_QTY)
VALUES ( 1 , 'Something', coalesce((select my_qty from mytable where my_id = 1), 0) + 7)
Although I really can't see any reasons you would want to do it this way. Have you considered writing a procedure that would encapsulate your desidered behaviour?
> I've tried, but no luck: UPDATE OR INSERT INTO MYTABLE (MY_ID, NAME,You can't use old and new in this context.
> MY_QTY) VALUES ( 1 , 'Something', OLD.MY_QTY + 7)
>
Sasha