From richard@ibisaustralia.com Fri Sep 26 05:16:26 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 5C408D1B544 for ; Fri, 26 Sep 2003 05:16:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 26848-04 for ; Fri, 26 Sep 2003 02:15:56 -0300 (ADT) Received: from server146.hostingrevolution.com (unknown [64.21.143.245]) by svr1.postgresql.org (Postfix) with ESMTP id DA130D1B4E8 for ; Fri, 26 Sep 2003 02:15:54 -0300 (ADT) Received: from 143.a.004.pth.iprimus.net.au ([211.26.96.143] helo=athlon2000) by server146.hostingrevolution.com with smtp (Exim 4.23) id 1A2kxv-0003LL-4t for pgsql-sql@postgresql.org; Fri, 26 Sep 2003 00:16:06 -0500 Message-ID: <002901c383ed$a70423a0$8f601ad3@athlon2000> From: "Richard Sydney-Smith" To: Subject: Date interval Date: Fri, 26 Sep 2003 13:18:27 +0800 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0020_01C38430.ABDBEF00" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server146.hostingrevolution.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - ibisaustralia.com X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=HTML_50_60 X-Spam-Level: X-Archive-Number: 200309/322 X-Sequence-Number: 15300 This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C38430.ABDBEF00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I am looking for a way to convert an interval into a number of days ( integ= er); In sybase I would use : days(today()-r_expire) where r_expire is the timestamp I am comparing against. How do we do this in postgres? date_trunc(today()-r_expire) does not seem to do it thanks=20 Richard ------=_NextPart_000_0020_01C38430.ABDBEF00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I am looking for a way to convert an inter= val into=20 a number of days ( integer);
 
In sybase I would use :
 
days(today()-r_expire)
 
where r_expire is the timestamp I am compa= ring=20 against.
 
How do we do this in postgres?
 
date_trunc(today()-r_expire) does not seem= to do=20 it
 
thanks
 
Richard
 
------=_NextPart_000_0020_01C38430.ABDBEF00-- From jasiek@klaster.net Fri Sep 26 05:58:26 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 49C81D1B501 for ; Fri, 26 Sep 2003 05:58:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 33675-08 for ; Fri, 26 Sep 2003 02:57:56 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id 6A71AD1B52D for ; Fri, 26 Sep 2003 02:57:53 -0300 (ADT) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id D01AA2B3E9; Fri, 26 Sep 2003 07:57:44 +0200 (CEST) Message-ID: <3F73D55E.6030405@klaster.net> Date: Fri, 26 Sep 2003 07:57:50 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5) Gecko/20030916 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Richard Sydney-Smith Cc: pgsql-sql@postgresql.org Subject: Re: Date interval References: <002901c383ed$a70423a0$8f601ad3@athlon2000> In-Reply-To: <002901c383ed$a70423a0$8f601ad3@athlon2000> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/323 X-Sequence-Number: 15301 > I am looking for a way to convert an interval into a number of days ( > integer); > > In sybase I would use : > > days(today()-r_expire) > > where r_expire is the timestamp I am comparing against. > > How do we do this in postgres? > > date_trunc(today()-r_expire) does not seem to do it select extract(epoch from some_interval)/3600/24::integer Regards, Tomasz Myrta From sad@bankir.ru Fri Sep 26 06:13:32 2003 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id BFF27D1B4FF for ; Fri, 26 Sep 2003 06:13:32 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 38022-04 for ; Fri, 26 Sep 2003 03:13:02 -0300 (ADT) Received: from rock.spider.ru (rock.spider.ru [62.183.34.226]) by svr1.postgresql.org (Postfix) with ESMTP id 74995D1B50A for ; Fri, 26 Sep 2003 03:13:00 -0300 (ADT) Received: from rock (localhost [127.0.0.1]) by rock (Postfix) with SMTP id 9BB889122F for ; Fri, 26 Sep 2003 10:12:59 +0400 (MSD) Received: from sad.localnet.ru (sad.localnet.ru [10.0.0.33]) by rock.spider.ru (Postfix) with ESMTP id 58A819121D for ; Fri, 26 Sep 2003 10:12:59 +0400 (MSD) Content-Type: text/plain; charset="iso-8859-1" From: sad Organization: IT To: Subject: Re: Date interval Date: Fri, 26 Sep 2003 10:16:10 +0400 User-Agent: KMail/1.4.3 References: <002901c383ed$a70423a0$8f601ad3@athlon2000> In-Reply-To: <002901c383ed$a70423a0$8f601ad3@athlon2000> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200309261016.10724.sad@bankir.ru> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/324 X-Sequence-Number: 15302 On Friday 26 September 2003 09:18, you wrote: > I am looking for a way to convert an interval into a number of days ( > integer); > > In sybase I would use : > > days(today()-r_expire) SELECT now()::DATE - '1900-12-10'::DATE; ?column?=20=20=20=20=20=20=20=20=20=20=20=20 -------------------------------- 37545 SELECT now()-'1900-12-10'::timestamp; ?column?=20=20=20=20=20=20=20=20=20=20=20=20 -------------------------------- 37545 days 06:10:54.2021608353 From meluzyna@w3.net.pl Tue Dec 6 16:50:36 2005 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2BCAF9DD5E4 for ; Tue, 6 Dec 2005 12:50:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 42858-03 for ; Tue, 6 Dec 2005 12:50:34 -0400 (AST) X-Greylist: delayed 03:00:55.212051 by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by postgresql.org (Postfix) with ESMTP id 9D2A49DCCF1 for ; Tue, 6 Dec 2005 12:50:33 -0400 (AST) Received: from spinet.pl (dagger.spinet.pl [195.205.122.6]) by svr2.postgresql.org (Postfix) with ESMTP id 4BCFDF0B5D for ; Tue, 6 Dec 2005 13:49:44 +0000 (GMT) Received: from localhost (localhost [127.0.0.1]) by spinet.pl (Postfix) with ESMTP id 55DDC13E35 for ; Tue, 6 Dec 2005 14:59:09 +0100 (CET) Received: from spinet.pl ([127.0.0.1]) by localhost (dagger [127.0.0.1]) (amavisd-new, port 10024) with SMTP id 31028-07 for ; Tue, 6 Dec 2005 14:59:08 +0100 (CET) Received: by spinet.pl (Postfix, from userid 65534) id 3F5B314071; Tue, 6 Dec 2005 14:59:08 +0100 (CET) Received: from hackstation (abv130.internetdsl.tpnet.pl [83.16.47.130]) by spinet.pl (Postfix) with ESMTP id ECA9713E35 for ; Tue, 6 Dec 2005 14:59:06 +0100 (CET) From: "Magdalena Komorowska" To: Subject: Date Interval Date: Tue, 6 Dec 2005 14:49:33 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 Thread-Index: AcX6a+M43xtpay2YQYWYqptgn1UzDQ== Message-Id: <20051206135906.ECA9713E35@spinet.pl> X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at spinet.pl X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.332 required=5 tests=[RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.332 X-Spam-Level: * X-Archive-Number: 200512/46 X-Sequence-Number: 23588 Hi, I hale a problem with counting interwal and I can't find what to do with this. I have two fields in the table: Column | Type | Modifiers -----------------+---------+----------- date_in | date | interwal_months | numeric | -----------------+---------+----------- Query SELECT date_in + INTERVAL '3 MONTH' FROM any_table works fine of course. However, how to do something like that? SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table I hope I'm just blind.. ;-) Thanks for any help. MK From pgman@candle.pha.pa.us Tue Dec 6 16:54:15 2005 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4B44D9DCCC4 for ; Tue, 6 Dec 2005 12:54:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41259-09 for ; Tue, 6 Dec 2005 12:54:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126]) by postgresql.org (Postfix) with ESMTP id 8E6A49DCAB0 for ; Tue, 6 Dec 2005 12:54:10 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id jB6Gs5d14178; Tue, 6 Dec 2005 11:54:05 -0500 (EST) From: Bruce Momjian Message-Id: <200512061654.jB6Gs5d14178@candle.pha.pa.us> Subject: Re: Date Interval In-Reply-To: <20051206135906.ECA9713E35@spinet.pl> To: Magdalena Komorowska Date: Tue, 6 Dec 2005 11:54:05 -0500 (EST) CC: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014] X-Spam-Score: 0.014 X-Spam-Level: X-Archive-Number: 200512/47 X-Sequence-Number: 23589 Magdalena Komorowska wrote: > Hi, > I hale a problem with counting interwal and I can't find what to do with > this. > I have two fields in the table: > Column | Type | Modifiers > -----------------+---------+----------- > date_in | date | > interwal_months | numeric | > -----------------+---------+----------- > > Query > SELECT date_in + INTERVAL '3 MONTH' FROM any_table > works fine of course. > > However, how to do something like that? > SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table How about this? test=> CREATE TABLE test(x TEXT); CREATE TABLE test=> INSERT INTO test VALUES ('3'); INSERT 0 1 test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM test; ?column? ------------------------------- 2006-03-06 11:53:05.574279-05 (1 row) -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073 From mike@fuhr.org Tue Dec 6 17:09:17 2005 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6F6689DCC26 for ; Tue, 6 Dec 2005 13:09:17 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 44312-10 for ; Tue, 6 Dec 2005 13:09:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 17A5F9DCAEF for ; Tue, 6 Dec 2005 13:09:14 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jB6H92mK075958 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 6 Dec 2005 10:09:05 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jB6H92iQ097225; Tue, 6 Dec 2005 10:09:02 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jB6H92bA097224; Tue, 6 Dec 2005 10:09:02 -0700 (MST) (envelope-from mfuhr) Date: Tue, 6 Dec 2005 10:09:02 -0700 From: Michael Fuhr To: Bruce Momjian Cc: Magdalena Komorowska , pgsql-sql@postgresql.org Subject: Re: Date Interval Message-ID: <20051206170902.GA97204@winnie.fuhr.org> References: <20051206135906.ECA9713E35@spinet.pl> <200512061654.jB6Gs5d14178@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200512061654.jB6Gs5d14178@candle.pha.pa.us> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[UPPERCASE_25_50=0] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/48 X-Sequence-Number: 23590 On Tue, Dec 06, 2005 at 11:54:05AM -0500, Bruce Momjian wrote: > test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM > test; > ?column? > ------------------------------- > 2006-03-06 11:53:05.574279-05 > (1 row) Or another way: test=> CREATE TABLE test (x numeric); CREATE TABLE test=> INSERT INTO test VALUES (3); INSERT 0 1 test=> SELECT current_timestamp + x * interval'1 month' FROM test; ?column? ------------------------------- 2006-03-06 12:07:48.112765-05 (1 row) -- Michael Fuhr From hf0923x@protecting.net Tue Dec 6 17:30:56 2005 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id AF15B9DCCC4 for ; Tue, 6 Dec 2005 13:30:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 48521-04 for ; Tue, 6 Dec 2005 13:30:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by postgresql.org (Postfix) with ESMTP id 2A4629DCCB8 for ; Tue, 6 Dec 2005 13:30:53 -0400 (AST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by svr2.postgresql.org (Postfix) with ESMTP id A77B2F0C77 for ; Tue, 6 Dec 2005 17:30:53 +0000 (GMT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EjgVN-0003AD-A9 for pgsql-sql@postgresql.org; Tue, 06 Dec 2005 18:21:29 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Dec 2005 18:21:29 +0100 Received: from hf0923x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Dec 2005 18:21:29 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Date Interval Date: 06 Dec 2005 18:15:24 +0100 Organization: Linux Private Site Lines: 38 Message-ID: <87k6eixi37.fsf@srv.protecting.net> References: <20051206135906.ECA9713E35@spinet.pl> <200512061654.jB6Gs5d14178@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.332 required=5 tests=[RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.332 X-Spam-Level: * X-Archive-Number: 200512/50 X-Sequence-Number: 23592 In article <200512061654.jB6Gs5d14178@candle.pha.pa.us>, Bruce Momjian writes: > Magdalena Komorowska wrote: >> Hi, >> I hale a problem with counting interwal and I can't find what to do with >> this. >> I have two fields in the table: >> Column | Type | Modifiers >> -----------------+---------+----------- >> date_in | date | >> interwal_months | numeric | >> -----------------+---------+----------- >> >> Query >> SELECT date_in + INTERVAL '3 MONTH' FROM any_table >> works fine of course. >> >> However, how to do something like that? >> SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table > How about this? > test=> CREATE TABLE test(x TEXT); > CREATE TABLE > test=> INSERT INTO test VALUES ('3'); > INSERT 0 1 > test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM > test; > ?column? > ------------------------------- > 2006-03-06 11:53:05.574279-05 > (1 row) Since Magdalena doesn't store the number of months in a string, the following might be more convenient: SELECT date_in + interwal_months * INTERVAL '1 MONTH' FROM any_table From meluzyna@w3.net.pl Tue Dec 6 17:47:02 2005 X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 1A3AE9DCAAF for ; Tue, 6 Dec 2005 13:47:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50214-09 for ; Tue, 6 Dec 2005 13:46:57 -0400 (AST) X-Greylist: delayed 03:57:20.606702 by SQLgrey- Received: from spinet.pl (dagger.spinet.pl [195.205.122.6]) by postgresql.org (Postfix) with ESMTP id D9D819DD44E for ; Tue, 6 Dec 2005 13:46:55 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by spinet.pl (Postfix) with ESMTP id A088E13F8C for ; Tue, 6 Dec 2005 18:56:27 +0100 (CET) Received: from spinet.pl ([127.0.0.1]) by localhost (dagger [127.0.0.1]) (amavisd-new, port 10024) with SMTP id 30578-03 for ; Tue, 6 Dec 2005 18:56:26 +0100 (CET) Received: by spinet.pl (Postfix, from userid 65534) id C9ED01403D; Tue, 6 Dec 2005 18:56:26 +0100 (CET) Received: from hackstation (abv130.internetdsl.tpnet.pl [83.16.47.130]) by spinet.pl (Postfix) with ESMTP id 9426413F8C for ; Tue, 6 Dec 2005 18:56:25 +0100 (CET) From: "Magdalena Komorowska" To: Subject: Re: Date Interval Date: Tue, 6 Dec 2005 18:46:50 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 In-Reply-To: <20051206135906.ECA9713E35@spinet.pl> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.1830 Thread-Index: AcX6a+M43xtpay2YQYWYqptgn1UzDQAHyhJg Message-Id: <20051206175625.9426413F8C@spinet.pl> X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at spinet.pl X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.666 required=5 tests=[AWL=0.666] X-Spam-Score: 0.666 X-Spam-Level: X-Archive-Number: 200512/51 X-Sequence-Number: 23593 It works great, very nice method :-) thanks a lot! MK