var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Auto update a field
Hello. I have a table with a follow fields:
I need update a the field status if the date_next < current_date.
This update need to be automatic. The check would be maked daily.
In DB2 i maked a Event Monitor. But how i can make this in PostgreSQL?
I'm using the PostgreSQL 8.2.
Don't update anything.
Create a view that returns the status based on the current_date
But the idea is, if the date_next is less than the current date, the status field must be updated.
Currently the update is done manually. I would like to automate this update.
No, you don't need the update. Just create a view that calculates the status "on-the-fly" and retrieve the status information through the view.
One rule in relational databases: do not store things you can determine from existing data.
CREATE VIEW status_info
when date_next < current_date then 'STATUS_ONE'
end as status
If your application cannot be changed to use the view, rename the table, create the view with the name of the table and create RULEs to make the view updateable.
Then you never need to worry about the status column, it will always be correct without any background jobs.
Tags for this Thread