Re: Function Help

From: "Brian C(dot) Doyle" <bcdoyle(at)mindspring(dot)com>
To: merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz)
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Function Help
Date: 2001-09-25 00:30:55
Message-ID: 5.0.2.1.0.20010924202954.009f76d0@pop.mindspring.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The main reason is that I am not quering a table with it as of yet...
Ultimately it will before query that is a Month do date query that does not
use a calender month

At 05:29 PM 9/24/01 -0700, Randal L. Schwartz wrote:
> >>>>> "Brian" == Brian C Doyle <bcdoyle(at)mindspring(dot)com> writes:
>
>Brian> Hello all,
>Brian> I am working on a function to determine the date of the first saturday
>Brian> of the month.
>
>Brian> Currently I have:
>
>Brian> CREATE FUNCTION first_saturday(date)
>Brian> RETURNS date
>Brian> AS '
>Brian> Select CASE WHEN date_part(\'dow\',\'$1\'::DATE)=0 THEN date(\'$1\')+6
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=1 THEN date(\'$1\')+5
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=2 THEN date(\'$1\')+4
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=3 THEN date(\'$1\')+3
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=4 THEN date(\'$1\')+2
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=5 THEN date(\'$1\')+1
>Brian> WHEN date_part(\'dow\',\'$1\'::DATE)=6 THEN date(\'$1\')+0
>Brian> END'LANGUAGE 'sql'
>
>Brian> I get an error that $1 is not a valid date. But I want that to be the
>Brian> variable I enter...
>Brian> what Am I doing wrong???
>
>Working too hard? :)
>
>why not just:
>
>My_Col + 6 - date_part('dow', My_Col)
>
>Don't even need a function for that. :)
>
>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
><merlyn(at)stonehenge(dot)com> <URL:http://www.stonehenge.com/merlyn/>
>Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
>See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Lee Harr 2001-09-25 00:37:21 Re: My brain hurts - update field based on value of another table's field
Previous Message Randal L. Schwartz 2001-09-25 00:29:19 Re: Function Help