I record the start time for a transaction in my database, and I have a time limit for each such transaction. I want to raise an alarm when it is timed out. Here are two ways I can think of doing this.
1) Let database do the calculation automatically so I can select records that exceed the limit.
2) Call the function from my script, give the current time, and calculate the time for each transaction in the database, then select aged ones.
I prefer the first solution, but I don’t know how to do that. I am using Postgresql. Anyone help me? Thanks.
In Postgres, you can use arithmetic operators with time values. See here: http://www.postgresql.org/docs/8.0/static/functions-datetime.html
You can also make a literal value of “interval” type, which represents a start-time and duration (or start and stop times, depending how you prefer to think about it).
So you could do something like (not yet tested):