I have table adv_days(adv_date date not null primary key, edit_state integer)
and I want to do series of commands: check wether '27.11.2019' exists in table, if exists then update edit_state to 1, if does not exist, then insert date '27.11.2019' with edit_state=1.
I have come up with Firebrid merge statement:
merge into adv_days d
using (select adv_date, edit_state from adv_days where adv_date='27.11.2019') d2
on (d.adv_date=d2.adv_date)
when matched then update set d.edit_state=1
when not matched then
insert(adv_date, edit_state)
values(:adv_date, 1);
It compiles and works as expected, but all the examples that I have read for merge is about application to 2 tables. So - maybe there is better solution for select-check-update operatios for one table than merge?
This is design question, but so concrete that SO is more appropriate than software engineering.