Hi everyone!

I'm trying to solve the following problem... Suppose every access to the
database is made as INSERTs (even UPDATEs). Whenever someone tries to insert
something ovver an existing row (i.e., same PK), that insert should be
treated as an update.

Example:

CREATE TABLE X ( c1 varchar, c2 varchar, c3 varchar, primary key c3)

INSERT INTO X (c1, c3) VALUES(1, 'a')
INSERT INTO X (c1, c2) VALUES(1, 'b') --> UPDATE X set c2 = 'b' WHERE c1 = 1

I haven't yet found any way to do this correctly. If I use the PRIMARY KEY x
ON CONFLICT REPLACE, the original row would be deleted. I don't want that, I
just want it to update the sent fields.

If I use a trigger I can only check if a column is null or not, but this
doesn't tell me if the original clause actually wanted to write a NULL, or
if it simply didn't specified the column (two completely different
scenarios). For example:

INSERT INTO X (c1, c2, c3) VALUES(1, null, 'a') --> UPDATE X set c2 = null,
c3 = 'a'  WHERE c1 = 1
INSERT INTO X (c1, c3) VALUES(1, 'a') --> UPDATE X set c3 = 'a'  WHERE c1 =
1

Thanks for any help/ideas you may have!

Cheers!

Hugo Ferreira

-- 
スプーンが ない

Reply via email to