I have a table whose Primary key is 1 and the other column is roll number.
I want to check if the id value is present in table, if yes update its roll number. If not insert the id and roll number in table.
I am trying to do it using merge.
parameters: id_value, roll_number
merge into "test_table" as t
using (SELECT * from "test_table" where id = id_value) as s
on t.id=s.id
when matched then
update set t.roll_number=5
when not matched then
insert (id, roll_number) values (id_value,roll_number);
It works when the value exists it updates the table but not in case of insert. No row is inserted.