Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 391A3476115 for ; Tue, 26 Nov 2002 06:00:17 -0500 (EST) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by postgresql.org (Postfix) with ESMTP id 832E9475E18 for ; Tue, 26 Nov 2002 06:00:03 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 18GdRi-0005re-0U; Tue, 26 Nov 2002 11:00:02 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id C843717096; Tue, 26 Nov 2002 10:51:22 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 26CF917008; Tue, 26 Nov 2002 10:51:22 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: nonsolosoft@diff.org, pgsql-sql@postgresql.org Subject: Re: PL/SQL trouble Date: Tue, 26 Nov 2002 10:51:18 +0000 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200211261051.18844.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/364 X-Sequence-Number: 10506 On Tuesday 26 Nov 2002 8:56 am, Ferruccio Zamuner wrote: > CREATE FUNCTION MONDAY(timestamp) RETURNS DATE AS ' > DECLARE > var1 date; > BEGIN > select into var1 to_date($1::date-(case when extract(DOW from > timestamp $1) =3D 0 then 6 else (extract(DOW from timestamp $1)-1) end)); > RETURN var1; > END' > language 'plpgsql'; The problem is the to_date(...) - the value is already a date so there isn'= t a=20 to_date that takes a date. You can also remove the timestamp casts: select into var1 ($1::date - (case when extract(DOW from $1) =3D 0=20 then 6 else (extract(DOW from $1) - 1 ) end ) ); If you put your function in a text file and create it with psql -f you can= =20 pinpoint errors more easily. In this case, the $2 was complaining about the second (expected) paramater = to=20 to_date I think. --=20 Richard Huxton