PostgreSQL reset a value to default daily?
I have my own database server that is on 24/7. What I want is to have a column that will reset its value to default daily. How do I do this?
Table(Int ColmA, ColmB)
ColmA has a default value of 5 and it will get decrement by some application. How do i make it to reset the value back to 5 daily?
The easiest way is to use crontab. Run in terminal:
(on some systems you need to switch to postgres user beforehand: sudo su postgres && crontab -e) and type in editor something like:
0 0 * * * psql <your_database_name> -c "UPDATE YourTable SET ColmA = 5"
Quit the editor. From now on every midnight UPDATE query will be executed.