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 4570632A0DA for ; Tue, 5 Oct 2004 13:29:14 +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 82259-10 for ; Tue, 5 Oct 2004 12:29:09 +0000 (GMT) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id 6BA9732A0BB for ; Tue, 5 Oct 2004 13:29:10 +0100 (BST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id i95BivCC017898; Tue, 5 Oct 2004 14:44:57 +0300 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id i95Biupt017894; Tue, 5 Oct 2004 14:44:57 +0300 Date: Tue, 5 Oct 2004 14:44:56 +0300 (EEST) From: Achilleus Mantzios To: Erik Wasser Cc: pgsql-sql@postgresql.org Subject: Re: Howto turn an integer into an interval? In-Reply-To: <200410051407.42037.erik.wasser@iquer.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT 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/26 X-Sequence-Number: 19129 O Erik Wasser έγραψε στις Oct 5, 2004 : > Hi List, > > I got a table named foobar with two fields > > last_sms is a 'timestamp without timezone' > resend_interval is a 'integer' > > I choose 'integer' for resend_interval rather than a 'interval' because > the frontend can easier handle the number of seconds. But now I'm stuck > with the query to get all rows that we're older than 'resend_interval' > in seconds. > > My first try was: > > SELECT * > FROM sms_groups > WHERE > (current_timestamp - last_sms) > '3600 seconds'::interval > > This is working great and returns all rows that are older than a hour. > But how I do this with the colum 'resend_interval' in the query? > > SELECT * > FROM sms_groups > WHERE > (current_timestamp - last_sms) > resend_interval::interval > > gives me only a "cannot cast type integer to interval". So how can I > turn an integer to an interval? Or is there an other solution? > Suggestions? If you know for sure that you are keeping resend_interval in seconds, then try as follows: foodb=# SELECT (59::text||' secs')::interval; interval ---------- 00:00:59 (1 row) foodb=# SELECT (120::text||' secs')::interval; interval ---------- 00:02:00 (1 row) foodb=# SELECT ((3600*25)::text||' secs')::interval; interval ---------------- 1 day 01:00:00 (1 row) foodb=# > > P.S: I'm using psql '7.4.5' of gentoo. > > -- -Achilleus