Re: querying the age of a row - Mailing list pgsql-general

From codeWarrior
Subject Re: querying the age of a row
Date
Msg-id f49hls$1s2f$1@news.hub.org
Whole thread Raw
In response to querying the age of a row  ("Lonni J Friedman" <netllama@gmail.com>)
Responses Re: querying the age of a row  ("Lonni J Friedman" <netllama@gmail.com>)
List pgsql-general
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@gmail.com> wrote in message
news:7c1574a90706071047x773c7085yf0d9f100dbca51da@mail.gmail.com...
> 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@gmail.com
> LlamaLand                       http://netllama.linux-sxs.org
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>



pgsql-general by date:

Previous
From: "Anton Melser"
Date:
Subject: Re: should the postgres user have a password?
Next
From: Scott Marlowe
Date:
Subject: Re: should the postgres user have a password?