Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 9ADF56324F2 for ; Tue, 19 May 2009 06:30:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34225-06 for ; Tue, 19 May 2009 06:30:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.ptn-ipout02.plus.net (relay.ptn-ipout02.plus.net [212.159.7.36]) by mail.postgresql.org (Postfix) with ESMTP id 028F163244D for ; Tue, 19 May 2009 06:30:24 -0300 (ADT) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAIAYEkrUnw6U/2dsb2JhbADOH4QBBQ Received: from fhw-relay07.plus.net ([212.159.14.148]) by relay.ptn-ipout02.plus.net with ESMTP; 19 May 2009 10:30:23 +0100 Received: from [84.51.143.99] (helo=server3.office.archonet.com) by fhw-relay07.plus.net with esmtp (Exim) id 1M6LeN-0006KA-11; Tue, 19 May 2009 10:30:19 +0100 Received: from dell36.office.archonet.com (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 65F40274049; Tue, 19 May 2009 10:30:22 +0100 (BST) Message-ID: <4A127C2E.1020701@archonet.com> Date: Tue, 19 May 2009 10:30:22 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.21 (X11/20090320) MIME-Version: 1.0 To: Sebastien FLAESCH CC: pgsql-general@postgresql.org Subject: Re: INTERVAL SECOND limited to 59 seconds? References: <4A127038.3010103@4js.com> <4A12737F.1020207@archonet.com> <4A127919.7080105@4js.com> In-Reply-To: <4A127919.7080105@4js.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 30a463581b39c12469155d477cee2cd0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200905/624 X-Sequence-Number: 147762 Sebastien FLAESCH wrote: > I think it should be clarified in the documentation... Please don't top-quote. And yes, I think you're right. Hmm a quick google for: [sql "interval second"] suggests that it's not the right thing. I see some mention of 2 digit precision for a leading field, but no "clipping". Looking at the manuals and indeed a quick \dT I don't see "interval second" listed as a separate type though. A bit of exploring in pg_attribute with a test table suggests it's just using "interval" with a type modifier. Which you seem to confirm from the docs: > The PostgreSQL documentation says: > > The interval type has an additional option, which is to restrict the set > of stored > fields by writing one of these phrases: > > YEAR > MONTH ... > Does that mean that the [field] option of the INTERVAL type is just > there to save > storage space? My trusty copy of the 8.3 source suggests that AdjustIntervalForTypmod() is the function we're interested in and it lives in backend/utils/adt/timestamp.c - it looks like it just zeroes out the fields you aren't interested in. No space saving. So - not a bug, but perhaps not the behaviour you would expect. > Actually I would like to use this new INTERVAL type to store > IBM/Informix INTERVALs, > which can actually be used like this with DATETIME types: > > > create table t1 ( > > k int, > > dt1 datetime hour to minute, > > dt2 datetime hour to minute, > > i interval hour(5) to minute ); > Table created. > > > insert into t1 values ( 1, '14:45', '05:10', '-145:10' ); > 1 row(s) inserted. > > > select dt1 - dt2 from t1; > (expression) > 9:35 <- INTERVAL expression SELECT ('14:45'::time - '05:10'::time); ?column? ---------- 09:35:00 (1 row) > > select 15 * ( dt1 - dt2 ) from t1; > (expression) > 143:45 <- INTERVAL expressio => SELECT 15 * ('14:45'::time - '05:10'::time); ?column? ----------- 143:45:00 (1 row) If you can live with the zero seconds appearing, it should all just work*. Other than formatting as text, I don't know of a way to suppress them though. * Depending on whether you need to round up if you ever get odd seconds etc. -- Richard Huxton Archonet Ltd