X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6126E475CBC for ; Wed, 26 Mar 2003 04:50:16 -0500 (EST) Received: from smtp.blueyonder.co.uk (pc-62-31-245-32-gl.blueyonder.co.uk [62.31.245.32]) by postgresql.org (Postfix) with ESMTP id 77DA4474E44 for ; Wed, 26 Mar 2003 04:50:15 -0500 (EST) Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 18y7Y9-0001RB-00 for pgsql-sql@postgresql.org; Wed, 26 Mar 2003 09:50:25 +0000 Date: Wed, 26 Mar 2003 09:50:24 +0000 (GMT) From: Peter Childs X-X-Sender: peter@RedDragon.Childs Cc: pgsql-sql@postgresql.org Subject: Re: Does anyone use TO_CHAR(INTERVAL)? In-Reply-To: <3E81620E.20604@klaster.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-32.1 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, QUOTE_TWICE_1,REPLY_WITH_QUOTES,USER_AGENT_PINE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/576 X-Sequence-Number: 12614 On Wed, 26 Mar 2003, Tomasz Myrta wrote: > > Thanks for noticing this, these results are really strange for me. > I should remember NOT to use months when working with intervals. It > looks like intervals contain 2 totally independent values inside. > > I have one more question to this thread - Does anyone use intervals > month value? Since all months are not equal in length how do else do you come up with an interval that is 1 month since us humans like to use months. As you note Postgres trys to ovide using Months if at all possible because 1 month <> 1 month hense. select (cast('2-2-2003' as date) + cast('1 month' as interval)) - cast('2-2-2003' as date); ?column? ---------- 28 days (1 row) but if all you say is 1 month from now how many days you month you mean will mean a different number of days. Oh one more good one is.... select cast('1 year' as interval) - cast('365 days' as interval); ?column? ------------------ 1 year -365 days (1 row) It would seam that a year is 12 months but not 365 days which while this is true (due to leap years) most people would never think like that. Its seams that postgres will not tell you how many days there are in a year but this seams even more stupid select cast('1 month' as interval)/2 * 2; ?column? ---------- 360 days (1 row) oh and just when you thought somthing was really straght forward you get... select cast('1 year' as interval)/24 * 24; ?column? ---------- 360 days (1 row) This reminds me of a calculator that comes with MS Windows.... How ever the implementation in postgres is the best I've sean so long as you don't do anything stupid! Peter Childs