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 157E752B04 for ; Mon, 15 Aug 2005 21:26:36 -0300 (ADT) 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 79414-03 for ; Tue, 16 Aug 2005 00:26:33 +0000 (GMT) Received: from priv-edtnes51.telusplanet.net (outbound04.telus.net [199.185.220.223]) by svr1.postgresql.org (Postfix) with ESMTP id 6B16252B8A for ; Mon, 15 Aug 2005 21:26:31 -0300 (ADT) Received: from localhost ([199.185.220.240]) by priv-edtnes51.telusplanet.net (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20050816002634.MMFV24517.priv-edtnes51.telusplanet.net@localhost> for ; Mon, 15 Aug 2005 18:26:34 -0600 Received: from 209.17.183.249 ( [209.17.183.249]) as user a3a18850@192.168.200.1 by webmail.telus.net with HTTP; Mon, 15 Aug 2005 17:26:34 -0700 Message-ID: <1124151994.430132baa4e4e@webmail.telus.net> Date: Mon, 15 Aug 2005 17:26:34 -0700 From: Mischa Sandberg To: pgsql-sql@postgresql.org Subject: Re: SQL output References: <84C5C116-630B-4363-AF37-FF38F9BBC813@gmail.com> In-Reply-To: <84C5C116-630B-4363-AF37-FF38F9BBC813@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1-cvs X-Originating-IP: 209.17.183.249 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.055 required=5 tests=[AWL=-0.371, DNS_FROM_RFC_POST=1.376, FORGED_RCVD_HELO=0.05] X-Spam-Level: * X-Archive-Number: 200508/106 X-Sequence-Number: 22334 Quoting Simon Law : > > CREATE TABLE tablename (field INTERVAL); > INSERT INTO tablename VALUES('3 weeks'); > SELECT field FROM tablename; > | 21 days | > > The output shows up in days or months but not weeks how do i make Internally, INTERVAL is stored as a 12byte tuple (years, months, days, hours, minutes, seconds, microseconds). It discards any knowledge of "weeks" (and "centuries" likewise) when it encodes the interval. So there's no way to force it to say "weeks" back to you. There is no datestyle that will do it for you, either. You can MANUALLY extract the number of days in the interval, and divide by 7 (round up or down, your choice). SELECT EXTRACT(DAYS FROM INTERVAL '3 WEEKS') Note, however, that if you define an interval with units greater than days (i.e. months or years) you'll get nothing, which is reasonable: months and years do not have fixed numbers of weeks in them.