Re: How to get CURRENT_DATE in a pl/pgSQL function

From: Kenneth Marshall <ktm(at)rice(dot)edu>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to get CURRENT_DATE in a pl/pgSQL function
Date: 2010-05-18 19:28:55
Message-ID: 20100518192855.GT3892@aart.is.rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 <richard(dot)broersma(at)gmail(dot)com>:
> > On Tue, May 18, 2010 at 12:08 PM, Kenneth Marshall <ktm(at)rice(dot)edu> 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(at)postgresql(dot)org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql
> >
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message David Harel 2010-05-18 21:29:40 plperlu user function.
Previous Message Kenneth Marshall 2010-05-18 19:27:21 Re: How to get CURRENT_DATE in a pl/pgSQL function