Help with simple function
От | Chris Hoover |
---|---|
Тема | Help with simple function |
Дата | |
Msg-id | 1d219a6f0512280649n3970fd99kbe6fb57f9dc7d102@mail.gmail.com обсуждение исходный текст |
Список | pgsql-admin |
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)
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)
В списке pgsql-admin по дате отправления: