From: Chris Hoover <revoohc@gmail.com>
To: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: Help with simple function
Date: Wed, 28 Dec 2005 09:49:08 -0500
Message-ID: <1d219a6f0512280649n3970fd99kbe6fb57f9dc7d102@mail.gmail.com> (raw)
I need some help. I am trying to get a very simple function written to help
our developers. Unfortunetly, the language we are developing in is giving
us some grief over trying to do a "select to_char((current_date - inteval '1
day'),'yyyymmdd') into x". It is complaining about the use of the work
interval.
Anyway, I thought, no problem, I'll just create a date increment and date
decrement set of functions. However, I can not get them to work. Can
someone please point out what is wrong?
CREATE OR REPLACE FUNCTION "public"."date_dec" (date, integer) RETURNS
varchar AS'
declare
startDate alias for $1;
numDays alias for $2;
retDate varchar(8);
begin
select to_char((startDate - interval ''numDays day''),''yyyymmdd'') into
retDate;
return retDate;
end;
'LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
When I try to run this, it complains about numDays - "Error: Bad interval
external representation 'numDays day'". Is there anyway around this? I am
trying to keep the function generic so that our developers can use it to
calculate any date range.
Thanks for any help,
Chris
PG7.3.4 (8.1.1 upgrade happening next month)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: revoohc@gmail.com
Subject: Re: Help with simple function
In-Reply-To: <1d219a6f0512280649n3970fd99kbe6fb57f9dc7d102@mail.gmail.com>
References: <1d219a6f0512280649n3970fd99kbe6fb57f9dc7d102@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox