Re: Function Help

From: "Brian C(dot) Doyle" <bcdoyle(at)mindspring(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function Help
Date: 2001-09-24 22:23:15
Message-ID: 5.0.2.1.0.20010924182259.00a90110@pop.mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

That was it... I knew it was something simple.. Thanks Peter!!!

At 11:06 PM 9/24/01 +0200, Peter Eisentraut wrote:
>Brian C. Doyle writes:
>
> > CREATE FUNCTION first_saturday(date)
> > RETURNS date
> > AS '
> > Select CASE WHEN date_part(\'dow\',\'$1\'::DATE)=0 THEN date(\'$1\')+6
> > WHEN date_part(\'dow\',\'$1\'::DATE)=1 THEN date(\'$1\')+5
> > WHEN date_part(\'dow\',\'$1\'::DATE)=2 THEN date(\'$1\')+4
> > WHEN date_part(\'dow\',\'$1\'::DATE)=3 THEN date(\'$1\')+3
> > WHEN date_part(\'dow\',\'$1\'::DATE)=4 THEN date(\'$1\')+2
> > WHEN date_part(\'dow\',\'$1\'::DATE)=5 THEN date(\'$1\')+1
> > WHEN date_part(\'dow\',\'$1\'::DATE)=6 THEN date(\'$1\')+0
> > END'LANGUAGE 'sql'
> >
> > I get an error that $1 is not a valid date.
>
>Don't quote the $1. E.g.,
>
>WHEN date_part(\'dow\',$1)=6 THEN date($1)+0
>
>The $1 etc. are not macros, they are identifiers representing a typed
>expression.
>
>--
>Peter Eisentraut peter_e(at)gmx(dot)net http://funkturm.homeip.net/~peter
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mayan 2001-09-25 00:18:35 Linking app to PgSQL
Previous Message snpe 2001-09-24 21:47:32 Re: Replication of distribudet databases & pgsql 7.2