I have a persistent table in SQLite (say PermTable). The schema for PermTable is
PermTable ( Node1 varchar(20), Node2 varchar(20), Node3 varchar(20), Frequency number, PRIMARY KEY (Node1, Node2, Node3))
I have a similar temporary table (say TempTable). TempTable has the same schema as PermTable.
For this question, let's assume the following content of PermTable and TempTable -
PermTable
Node1 | Node2 | Node3 | Frequency
_________________________________
A | B | C | 2
B | D | E | 3
TempTable
Node1 | Node2 | Node3 | Frequency
_________________________________
A | B | C | 6
D | E | C | 4
I would like to update/copy values from TempTable into PermTable such that if any similar entry exists, the frequency is summed, else a plain insert takes place.
EXPECTED OUTPUT:
PermTable
Node1 | Node2 | Node3 | Frequency
_________________________________
A | B | C | 8
B | D | E | 3
D | E | C | 4
I have looked into the links here, here or here. However, they either INSERT OR REPLACE
some hard-coded values, or they use some external programming interface to get the status of query execution and do the subsequent steps.
I have to stick with SQLite and as such constructs like UPSERT
, ON DUPLICATE KEY
, MERGE
, etc. is not favorable in this case.