I would like to force user to specify origin of update to some table (sometbl), eg. to specify 'local' or 'remote' (for col2) - but checking of that requirement should occur at DB level when UPDATE statement is executed so:
UPDATE sometbl SET col1 = 'abc';
should throw error (exception), but:
UPDATE sometbl SET col1 = 'abc', col2 = 'remote';
...will succeed.
I tried to create BEFORE update trigger for that table, but I was unable to check if NEW.col2 was explictly set.
I used condition
IF NEW.col2 IS NULL THEN
RAISE EXCEPTION 'you must specify source of this update (local/remote)'
END IF;
but every time, when col2 was not specified in update (UPDATE sometbl SET col1 = 'abc')
I got current value of that field in NEW.col2 pseudo-var, instead of supposed NULL.
Is there any workaround to prevent UPDATING row when specified field is not present in UPDATE stmt?