iburrell has asked for the wisdom of the Perl Monks concerning the following question:
MySQL specific:SELECT * FROM session WHERE EXTRACT(EPOCH FROM lastop) < EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) - $ +timeout
It is possible to do the calculation directly with timestamp values. The following is SQL92 standard, only supported by MySQL:SELECT * FROM session WHERE UNIX_TIMESTAMP(lastop) < UNIX_TIMESTAMP(CURRENT_TIMESTAMP) - $timeout
PostgreSQL uses a slightly different syntax (which I think is the SQL99 standard):SELECT * FROM session WHERE lastop < now() - interval $timeout second
Is there any way to do this portably?SELECT * FROM session WHERE lastop < now() - interval '$timeout second'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Portable database interval calculation
by perrin (Chancellor) on Oct 25, 2002 at 20:44 UTC | |
by princepawn (Parson) on Oct 25, 2002 at 20:53 UTC |