Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id DCC5B1336B42 for ; Tue, 8 Feb 2011 17:37:23 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 22764-07 for ; Tue, 8 Feb 2011 21:37:16 +0000 (UTC) X-Greylist: delayed 00:07:01.649723 by SQLgrey-1.7.6 Received: from mail-ew0-f46.google.com (mail-ew0-f46.google.com [209.85.215.46]) by mail.postgresql.org (Postfix) with ESMTP id 12EB11336971 for ; Tue, 8 Feb 2011 17:37:15 -0400 (AST) Received: by ewy5 with SMTP id 5so3314456ewy.19 for ; Tue, 08 Feb 2011 13:37:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.14.127.136 with SMTP id d8mr7663667eei.35.1297200613088; Tue, 08 Feb 2011 13:30:13 -0800 (PST) Received: by 10.14.47.10 with HTTP; Tue, 8 Feb 2011 13:30:13 -0800 (PST) Date: Tue, 8 Feb 2011 13:30:13 -0800 Message-ID: Subject: Missing documentation for uses of extract(field from interval) From: Daniel Grace To: pgsql-docs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/42 X-Sequence-Number: 6390 (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