Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 03341B5DBC4 for ; Mon, 15 Aug 2011 11:14:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 06505-09 for ; Mon, 15 Aug 2011 14:14:12 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yx0-f174.google.com (mail-yx0-f174.google.com [209.85.213.174]) by mail.postgresql.org (Postfix) with ESMTP id B2111B5D803 for ; Mon, 15 Aug 2011 11:14:12 -0300 (ADT) Received: by yxj19 with SMTP id 19so3136747yxj.19 for ; Mon, 15 Aug 2011 07:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to :mime-version:content-type:content-transfer-encoding:message-id; bh=LK9hFLR6m7lWzM5BpNt9UBRX1AgOD0uhwJnuh5aST/c=; b=BM6yYJfKSKvb6vzGHKBYc7qgz4uOTuxOgoj+ORGWPoB9KgQ/745DlydPbMnDgyeMOe /+8igkeItxfoPWBF+dVsNJjnpi6eerQWF4JmBQxvSu9UR/HfSCxhMW/Hb9+WydBgTsQH rCF44i1Lsvf7vcDILna+QEvxx7u0KRIslWxuk= Received: by 10.236.73.162 with SMTP id v22mr10605991yhd.199.1313417652861; Mon, 15 Aug 2011 07:14:12 -0700 (PDT) Received: from tucker.localnet (c-24-17-164-54.hsd1.wa.comcast.net [24.17.164.54]) by mx.google.com with ESMTPS id e21sm1159536yhn.63.2011.08.15.07.14.11 (version=SSLv3 cipher=OTHER); Mon, 15 Aug 2011 07:14:11 -0700 (PDT) From: Adrian Klaver To: Janiv Ratson Subject: Re: bigint and unix time Date: Mon, 15 Aug 2011 07:14:07 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.32-33-generic; KDE/4.4.5; i686; ; ) Cc: "pgsql-sql@postgresql.org" References: <9C103394ED80654B9DD6D9347E9D3001040F2014@es-ex1-il.essencesecurity.com> <201108141057.05589.adrian.klaver@gmail.com> <25B9D8D6D61CDB4CAD5D742B947F5C1A0493824C@ES-EX2010A-IL.essencesecurity.com> In-Reply-To: <25B9D8D6D61CDB4CAD5D742B947F5C1A0493824C@ES-EX2010A-IL.essencesecurity.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201108150714.08500.adrian.klaver@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.899 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201108/50 X-Sequence-Number: 35718 On Sunday, August 14, 2011 11:23:08 pm Janiv Ratson wrote: > Hi and thanks, > If my 'time' column is being saved as bigint: 1287323899000000. > How do I write a query to check if the 'time' field is greater than now - > 30 (past 30 days)? So what you want is not what values are greater than some point 30 days ago which is what your previous query asked and answered, but the values between a point 30 days ago and today. The easiest way is to use BETWEEN: test(5432)aklaver=>\d big_int_test Table "public.big_int_test" Column | Type | Modifiers --------+---------+----------- bint | bigint | rint | integer | test(5432)aklaver=>SELECT * from big_int_test ; bint | rint ------------------+------------ 1287323899000000 | 1310799600 test(5432)aklaver=>SELECT bint FROM big_int_test WHERE bint BETWEEN extract(epoch from (date 'now' - integer '30')) AND extract(epoch from (date 'now')); bint ------ (0 rows) That being said, if your time values are the order of magnitude shown they will not meet the criteria above. Is the time value supposed to be seconds? > > Thanks, > Janiv,. -- Adrian Klaver adrian.klaver@gmail.com