Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 0ED45633876 for ; Thu, 17 Sep 2009 14:40:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30463-05 for ; Thu, 17 Sep 2009 17:40:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from is.rice.edu (is.rice.edu [128.42.42.24]) by mail.postgresql.org (Postfix) with ESMTP id 1B30C63382E for ; Thu, 17 Sep 2009 14:40:02 -0300 (ADT) Received: from scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) by is.rice.edu (Postfix) with ESMTP id F0B394181C; Thu, 17 Sep 2009 12:40:00 -0500 (CDT) Received: from is.rice.edu ([128.42.42.24]) by scan1.mail.rice.edu (scan1.mail.rice.edu [128.42.58.160]) (amavisd-new, port 10024) with ESMTP id 05361-03; Thu, 17 Sep 2009 12:40:00 -0500 (CDT) Received: by is.rice.edu (Postfix, from userid 18612) id 3FCDE41819; Thu, 17 Sep 2009 12:40:00 -0500 (CDT) Date: Thu, 17 Sep 2009 12:39:59 -0500 From: Kenneth Marshall To: Gavin McCullagh Cc: pgsql-sql@postgresql.org Subject: Re: extracting from epoch values in pgsql Message-ID: <20090917173959.GE22802@it.is.rice.edu> References: <20090917164439.GU16815@gcd.ie> <4AB26B6F.4010207@sympatico.ca> <20090917173039.GV16815@gcd.ie> <20090917173439.GW16815@gcd.ie> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090917173439.GW16815@gcd.ie> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: by amavis-2.2.1 at scan1.mail.rice.edu X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-6.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599, RCVD_IN_DNSWL_MED=-4 X-Spam-Level: X-Archive-Number: 200909/94 X-Sequence-Number: 33159 On Thu, Sep 17, 2009 at 06:34:39PM +0100, Gavin McCullagh wrote: > On Thu, 17 Sep 2009, Gavin McCullagh wrote: > > > On Thu, 17 Sep 2009, Frank Bax wrote: > > > > > Gavin McCullagh wrote: > > >> SELECT time, to_timestamp(time) AS ts, > > >> EXTRACT('months',to_timestamp(time)) FROM mdl_log; > > >> ERROR: syntax error at or near "," > > >> LINE 1: ...t time, to_timestamp(time) AS ts, extract('months',to_times... > > > > > > Try replacing extract('month',value) with extract('months' from value) > > > > Makes no difference whether month or months: > > Actually, I pasted a different query, but based on the one in my last > email: > > moodle-01-01-2009=# SELECT EXTRACT('months',(TIMESTAMP WITH TIME ZONE 'epoch' + mdl_log.time * INTERVAL '1 second')) > FROM mdl_log; > ERROR: syntax error at or near "," > LINE 1: SELECT EXTRACT('months',(TIMESTAMP WITH TIME ZONE 'epoch' + ... > ^ > moodle-01-01-2009=# SELECT EXTRACT('month',(TIMESTAMP WITH TIME ZONE 'epoch' + mdl_log.time * INTERVAL '1 second')) > FROM mdl_log; > ERROR: syntax error at or near "," > LINE 1: SELECT EXTRACT('month',(TIMESTAMP WITH TIME ZONE 'epoch' + m... > ^ > > Gavin > Gavin, I think Frank had the answer: Try replacing extract('month',value) with extract('months' from value) Look at the documentation for the syntax for further details. Regards, Ken