determining the age of a row in postgresql?
Net Llama!
netllama
Thu Jun 7 14:54:54 PDT 2007
On Thu, 7 Jun 2007, Bill Campbell wrote:
> On Thu, Jun 07, 2007, Net Llama! wrote:
>> I'm pulling my hair out trying to find a means of determining the age of a
>> row in a table in a PostgreSQL database. I've googled, and found close to
>> nothing that doesn't require writing crazy triggers or altering the DB
>> schema. Surely this must be possible, right?
>
> I think one would need to have a time stamp column in the row for
> comparison purposes, particularly if one is to be database agnostic.
>
> One could have stored procedure(s) and triggers that updated this time when
> a row is created or changed.
I eventually figured this out with the following:
SELECT count(*) FROM ${table} WHERE (SELECT now() - interval '24
hours' < date_created::timestamp)='t' ;
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lonni J Friedman netllama at linux-sxs.org
LlamaLand http://netllama.linux-sxs.org
More information about the Linux-users
mailing list