I am writing a simulation application and wand to add values into a table if they exists or just insert these as new values.
Example table:
CREATE TABLE "time_table" ("time_abs" INTEGER UNIQUE , "volume" DOUBLE);
INSERT INTO "time_table" ("time_abs","volume") VALUES (5,20);
Here is what I want to do:
- Insert:
time_abs=5 volume=25 - before I do that it should just check if there is already a value at time_abs=5
- yes it is --> volume=20 (is already there) --> new volume=20+25 (old plus new volume)
- no it is not --> volume=25
- one query only, as I want to implement it into my Java method within batches and prepared statement...
I have found Eric B's answer (click), but I cannot add something like this to it:
UPDATE time_table SET volume=volume+25
Thank you for the attention and have a nice day.