From: | Peter Eisentraut <peter_e(at)gmx(dot)net> |
---|---|
To: | "Brian C(dot) Doyle" <bcdoyle(at)mindspring(dot)com> |
Cc: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Function Help |
Date: | 2001-09-24 21:06:58 |
Message-ID: | Pine.LNX.4.30.0109242304590.679-100000@peter.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Arcady Genkin | 2001-09-24 21:43:35 | Duplicate key errors and logging |
Previous Message | Kevin | 2001-09-24 21:00:06 | Bind/Define and Bulk copy -> Which interface? |