X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7ED033A3CC1 for ; Mon, 25 Oct 2004 03:54:41 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08023-04 for ; Mon, 25 Oct 2004 02:54:02 +0000 (GMT) Received: from smtp.bltconsult.com (smtp.bltconsult.com [64.124.68.186]) by svr1.postgresql.org (Postfix) with ESMTP id 198C73A3C48 for ; Mon, 25 Oct 2004 03:54:28 +0100 (BST) Received: from [138.89.132.102] (helo=LENNHOFF-PEXI.foo.bar) by 64.125.181.59 with asmtp (TLSv1:RC4-SHA:128) id 1CLv0G-0002lH-00 for ; Sun, 24 Oct 2004 22:54:36 -0400 Message-Id: <6.0.2.0.0.20041024224504.03b5c7c8@localhost> Date: Sun, 24 Oct 2004 22:54:33 -0400 To: pgsql-sql@postgresql.org From: Larry Lennhoff Subject: Create interval using column value? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/161 X-Sequence-Number: 19264 Hi I have a table (A) with a integer column called build_interval, which contains the number of milliseconds betweeen builds. I have another table (B) with a timestamp with timezone column called built_on. The two tables share a column called join_col. 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'; This does not work at all - I cannot find a way to build an interval using a column - casting an integer as an interval is forbidden. Can anyone suggest a way to achieve my desired result? I'm not wedded to the interval approach. I can probably change the column type of build_interval if necessary. I am using postgres 7.3.4 Thanks in advance for any help.