Re: [GENERAL] User defined function

From: "Aaron J(dot) Seigo" <aaron(at)gtv(dot)ca>
To: "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>, <greg(at)proterians(dot)net>
Cc: <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] User defined function
Date: 1999-10-15 18:58:15
Message-ID: 99101513005701.00558@stilborne
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aaron J. Seigo 1999-10-15 19:03:48 Re: [GENERAL] php - pgsql connection
Previous Message soundar rajan 1999-10-15 18:25:16 Re: [GENERAL] how to insert a date