Re: [GENERAL] User defined function

Поиск
Список
Период
Сортировка
От Aaron J. Seigo
Тема Re: [GENERAL] User defined function
Дата
Msg-id 99101513005701.00558@stilborne
обсуждение исходный текст
Ответ на Re: [GENERAL] User defined function  ("Moray McConnachie" <moray.mcconnachie@computing-services.oxford.ac.uk>)
Список pgsql-general
hi...

>
> >  CREATE FUNCTION startofregyear(date) RETURNS date AS '
> >  SELECT text_datetime(''01/12/''
> float8_text(datepart(''year'',$1)-1))
> >  AS answer;
>  > ' LANGUAGE 'SQL';
>
> absolutely not, I tried that already.
> I get "attribute not found" error  wherever the opening double-quotes
> are during the create of the function.

try this (it works quite nicely):
 select (''12-1-'' || date_part(''year'',$1) - 1)::date;

your problem is 2 fold. first, you need double quotes. second, it isn't
datepart, its date_part. that's the "attribute not found" error.

as a suggestion, try doing the select statement from the command line outside
of a function first to make sure it works. i.e:
  select ('12-1-' || date_part('year','now'::date) - 1)::date;

once you know that your select works, pop it into the function. functions don't
return the most helpful error messages =) the command line in psql is much
better for debugging selects/inserts/etc/etc...


 --
Aaron J. Seigo
Sys Admin

В списке pgsql-general по дате отправления:

Предыдущее
От: soundar rajan
Дата:
Сообщение: Re: [GENERAL] how to insert a date
Следующее
От: "Aaron J. Seigo"
Дата:
Сообщение: Re: [GENERAL] php - pgsql connection