Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id C5517632EDF for ; Tue, 18 May 2010 16:29:04 -0300 (ADT) 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 62271-06 for ; Tue, 18 May 2010 19:28:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh4.mail.rice.edu (mh4.mail.rice.edu [128.42.199.11]) by mail.postgresql.org (Postfix) with ESMTP id A45BC632DB9 for ; Tue, 18 May 2010 16:28:57 -0300 (ADT) Received: from mh4.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh4.mail.rice.edu (Postfix) with ESMTP id 8AA9C370066; Tue, 18 May 2010 14:28:56 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.0 at mh4.mail.rice.edu Received: from mh4.mail.rice.edu ([127.0.0.1]) by mh4.mail.rice.edu (mh4.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 04EqCqNAItBq; Tue, 18 May 2010 14:28:56 -0500 (CDT) Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh4.mail.rice.edu (Postfix) with ESMTP id 5355C37002D; Tue, 18 May 2010 14:28:56 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 20F3F2D5A6; Tue, 18 May 2010 14:28:56 -0500 (CDT) Date: Tue, 18 May 2010 14:28:55 -0500 From: Kenneth Marshall To: Pavel Stehule Cc: Richard Broersma , pgsql-sql@postgresql.org Subject: Re: How to get CURRENT_DATE in a pl/pgSQL function Message-ID: <20100518192855.GT3892@aart.is.rice.edu> References: <20100518190832.GQ3892@aart.is.rice.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201005/80 X-Sequence-Number: 34128 Okay, this works as well. Thank you for all of the assistance. Regards, Ken On Tue, May 18, 2010 at 09:25:00PM +0200, Pavel Stehule wrote: > 2010/5/18 Richard Broersma : > > On Tue, May 18, 2010 at 12:08 PM, Kenneth Marshall wrote: > > > >> http://www.postgresql.org/docs/8.4/static/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT > >> > >> you can use CURRENT_DATE. When I try to use it in > >> the following pl/pgSQL function it gives the error: > > > >> BEGIN > >> ?? ??curtime := 'CURRENT_DATE'; > >> ?? ??LOOP > > > > > > I'm not "up" on my pl/pgSQL, but isn't CURRENT_DATE a literal value so > > it shouldn't to be enclosed in single quotes? > > no - it is mutable constant > > postgres=# > CREATE OR REPLACE FUNCTION fo() > RETURNS date AS $$ > DECLARE d date; > BEGIN > d := CURRENT_DATE; > RETURN d; > END; > $$ LANGUAGE plpgsql; > CREATE FUNCTION > Time: 450.665 ms > postgres=# select fo(); > fo > ???????????????????????????????????? > 2010-05-18 > (1 row) > > > Regards > Pavel Stehule > > > > > Another idea would be to: ??CAST( now() AS DATE ) > > > > > > > > -- > > Regards, > > Richard Broersma Jr. > > > > Visit the Los Angeles PostgreSQL Users Group (LAPUG) > > http://pugs.postgresql.org/lapug > > > > -- > > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > > To make changes to your subscription: > > http://www.postgresql.org/mailpref/pgsql-sql > > >