Skip site navigation (1) Skip section navigation (2)

Re: Create interval using column value?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Larry Lennhoff <llennhoff-postgres(at)pexicom(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Create interval using column value?
Date: 2004-10-25 03:11:52
Message-ID: 9636.1098673912@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-sql
Larry Lennhoff <llennhoff-postgres(at)pexicom(dot)com> writes:
> What I want to do is find all the rows in 
> A which were built before now() - build_interval seconds ago.  If I could 
> just write this in SQL it would look something like:

> SELECT A.id FROM A JOIN B ON (join_col) WHERE built_on < now() - interval 
> 'build_interval seconds';

You are confused about the difference between a literal constant and an
expression.   Try something like

... WHERE built_on < now() - build_interval * interval '1 second';

which relies on the number-times-interval operator.

			regards, tom lane

In response to

Responses

pgsql-sql by date

Next:From: Michael GlaesemannDate: 2004-10-25 03:13:42
Subject: Re: Create interval using column value?
Previous:From: Larry LennhoffDate: 2004-10-25 02:54:33
Subject: Create interval using column value?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group