Is there a way in postgresql to have an auto-incrementing column reset back to zero at a specified time every day?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It could be pretty trivial with a cronjob
Alternately, you could set your “serial” column DEFAULT to call a stored procedure, which would check for a day rollover, reset the sequence if appropriate, and then return the result of nextval().
But other than that, no, I wouldn’t expect that there’s a magic ALTER SEQUENCE my_seq RESET AT INERVAL ‘1 day’ or anything like that.
Edit: incorporated duckyfuzz’s comment.