Re: querying the age of a row

From: "Lonni J Friedman" <netllama(at)gmail(dot)com>
To: codeWarrior <gpatnude(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: querying the age of a row
Date: 2007-06-07 18:21:12
Message-ID: 7c1574a90706071121j4b2ae624qcdfb00a177eafd65@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Unfortunately, its too late now. The database (and its tables) have
been around for a while, so even if I added this column, it wouldn't
help me for the thousands of pre-existing rows. Thanks though.

On 6/7/07, codeWarrior <gpatnude(at)hotmail(dot)com> wrote:
> Interesting issue --
>
> I have usually solved this by adding a specific field to each table with a
> default timestamp of NOW()...
>
> When you:
>
> CREATE TABLE tbl (
>
> blah...
> blah....
>
> create_dt TIMESTAMP NOT NULL DEFAULT NOW()
>
> );
>
> each and every record now has a timestamp of exactly when the row was
> created -- then it is a simple query to select, update, or delete WHERE
> create_dt < (NOW() - interval '1 day')...
>
>
> HTH....
>
>
> ""Lonni J Friedman"" <netllama(at)gmail(dot)com> wrote in message
> news:7c1574a90706071047x773c7085yf0d9f100dbca51da(at)mail(dot)gmail(dot)com(dot)(dot)(dot)
> > Greetings,
> > I've got a PostgreSQL-8.1.x database on a Linux box. I have a need to
> > determine which rows in a specific table are less than 24 hours old.
> > I've tried (and failed) to do this with the age() function. From what
> > I can tell, age() only has granularity down to days, and seems to
> > assume that anything matching today's date is less than 24 hours old,
> > even if there are rows from yesterday's date that existed less than 24
> > hours ago.
> >
> > I've googled on this off and on for a few days, and have come up dry.
> > At any rate, is there a reliable way of querying a table for rows
> > which have existed for a specific period of time?
> >

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L. Friedman netllama(at)gmail(dot)com
LlamaLand http://netllama.linux-sxs.org

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Glaesemann 2007-06-07 18:22:05 Re: subtract a day from the NOW function
Previous Message Sergei Shelukhin 2007-06-07 18:20:20 Re: insane index scan times