I'm trying to track how my data are changed,
I am working with custom solution because I will track those changes only when I run the script.
What is most important to me is to have previous_value
and value_after_update
INSERT INTO audit_details
(updated_table, updated_column, query, value_before_update, value_after_update)
SELECT 'some_table', 'some_column', query, enabled, (Here I've tried to put same query as it's contained on update because that value will be there after update),
FROM some_table WHERE product_id = _new_product_id;
UPDATE some_table
SET enabled = CASE WHEN (SELECT 1 FROM some_table WHERE enabled = true AND product_type = T1.product_type AND product_id = ANY(_previous_product_ids)) IS NOT NULL
THEN true
ELSE enabled END,
THEN true
ELSE accepted END
WHERE product_id = _new_product_id;
As you can notice guys, problem is that I don't know how can I properly insert also values_after_update
, I should somehow repeat
block from update into my insert into above (I have tried it even If I couldnt run it, it was big and ugly XD) ?
Any kind of help would be awesome!
Thanks
Cheers