Function Help

From: "Brian C(dot) Doyle" <doyleb(at)corp(dot)earthlink(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Function Help
Date: 2001-09-24 20:25:24
Message-ID: 5.1.0.14.2.20010924162341.04e39a40@proxy
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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???

Brian C. Doyle
Supervisor: Web Link
Earthlink Web Hosting Technical Support
webhelp(at)mindspring(dot)net

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Troy.Campano 2001-09-24 20:28:47 PostgreSQL on MAINFRAME
Previous Message Dominique Dumortier 2001-09-24 19:39:19 PostGres is not using indices in select, I would like it to because it is too slow !