Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 3B9E81337BBB for ; Fri, 11 Mar 2011 09:18:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 13291-06 for ; Fri, 11 Mar 2011 13:18:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from momjian.us (momjian.us [70.90.9.53]) by mail.postgresql.org (Postfix) with ESMTP id 954671337B80 for ; Fri, 11 Mar 2011 09:18:25 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id p2BDITc09295; Fri, 11 Mar 2011 08:18:29 -0500 (EST) From: Bruce Momjian Message-Id: <201103111318.p2BDITc09295@momjian.us> Subject: Re: Missing documentation for uses of extract(field from interval) In-Reply-To: To: Daniel Grace Date: Fri, 11 Mar 2011 08:18:29 -0500 (EST) CC: pgsql-docs@postgresql.org X-Mailer: ELM [version 2.4ME+ PL124 (25)] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ELM1299849509-10557-5_" Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/77 X-Sequence-Number: 6510 --ELM1299849509-10557-5_ Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" I have added documentation for EXTRACT(DAY) usage with intervals. We had something for MONTH, but for some reason nothing for DAY. Applied patch attached. --------------------------------------------------------------------------- Daniel Grace wrote: > (Note: I'm not subscribed to pgsql-docs, so please CC me on any > replies. Thanks!) > > I pulled up the documentation today to see if I could get just the > number of days in an interval using EXTRACT. The answer provided was > vague: While you can use EXTRACT(field from interval) (shown in table > 9-27), section 9.9.1 only lists: > > day > > The day (of the month) field (1 - 31) > > SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40'); > Result: 16 > > > > It turns out that EXTRACT(day FROM interval) does work as expected -- > so perhaps the documentation should be updated to something like: > > day > > The day (of the month) field (1 - 31), or the number of days in the interval > > SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40'); > Result: 16 > > SELECT EXTRACT(DAY FROM INTERVAL '42 days 21:00:00'); > Result: 42 > > Likewise for month, year, century and maybe some others. (hour, > minute, and *second{s?} probably don't need updated text). > > There also should probably be some warning in here about EXTRACT on > intervals however. Namely cases like this: > > SELECT EXTRACT(YEAR FROM INTERVAL '400 days') --> Result: 0 > (because the interval is '400 days' not '1 year 35 days') > SELECT EXTRACT(DAY FROM INTERVAL '1 year') --> Result: 0 (because > the interval is '1 year' not '365 days') > SELECT EXTRACT(DAY FROM INTERVAL '1 month') --> Result: 0 > > Though, this works: > SELECT EXTRACT(CENTURY FROM INTERVAL '99 years') --> Result: 0 > SELECT EXTRACT(CENTURY FROM INTERVAL '100 years') --> Result: 1 > -- > Daniel Grace > AGE, LLC > System Administrator and Software Developer > > -- > Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-docs -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --ELM1299849509-10557-5_ Content-Transfer-Encoding: 7bit Content-Type: text/x-diff Content-Disposition: inline; filename="/rtmp/interval.diff" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml new file mode 100644 index 4635cf2..c392109 *** a/doc/src/sgml/func.sgml --- b/doc/src/sgml/func.sgml *************** SELECT EXTRACT(CENTURY FROM TIMESTAMP '2 *** 6605,6617 **** day ! The day (of the month) field (1 - 31) SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40'); Result: 16 --- 6605,6624 ---- day ! For timestamp values, the day (of the month) field ! (1 - 31) ; for interval values, the number of days SELECT EXTRACT(DAY FROM TIMESTAMP '2001-02-16 20:38:40'); Result: 16 + + SELECT EXTRACT(DAY FROM INTERVAL '40 days 1 minute'); + Result: 40 + + + *************** SELECT EXTRACT(MINUTE FROM TIMESTAMP '20 *** 6827,6833 **** For timestamp values, the number of the month ! within the year (1 - 12) ; for interval values the number of months, modulo 12 (0 - 11) --- 6834,6840 ---- For timestamp values, the number of the month ! within the year (1 - 12) ; for interval values, the number of months, modulo 12 (0 - 11) --ELM1299849509-10557-5_--