Function Help - Mailing list pgsql-general

From Brian C. Doyle
Subject Function Help
Date
Msg-id 5.1.0.14.2.20010924162845.05426490@proxy
Whole thread Raw
Responses Re: Function Help
Re: Function Help
List pgsql-general
Hello all,

I am working on a function to determine the date of the first saturday of
the month.

Currently I have:

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.  But I want that to be the
variable I enter...
what Am I doing wrong???





pgsql-general by date:

Previous
From: R Talbot
Date:
Subject: Make failure on v. 7.1.2
Next
From: Lamar Owen
Date:
Subject: Re: Make failure on v. 7.1.2