Re: [GENERAL] User defined function

From: "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>
To: <greg(at)proterians(dot)net>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: [GENERAL] User defined function
Date: 1999-10-15 14:41:16
Message-ID: 02fb01bf171b$562b3010$760e01a3@oucs.ox.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I need to write a function to return the first of december of the
year
> previous to the current year. Part of my problem is I'm not sure how
> to escape quotes in function definitions. I am looking at something
> along the lines of
>
> CREATE FUNCTION startofregyear(date) RETURNS date AS '
> SELECT text_datetime('01/12/' ¦¦ float8_text(datepart('year',$1)-1))
> AS answer;
> ' LANGUAGE 'SQL';
>
> but clearly this won't work because of the large number of single
> quotes. I've tried escaping the quotes in the SELECT line with
> backslashes, but that doesn't seem to do it.
>
> Can anyone tell me if this function should work, once I sort out the
> escaping?
>
try using double quotas...

> 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.
----------------------------------------------------------------------
----------------
Moray(dot)McConnachie(at)computing-services(dot)oxford(dot)ac(dot)uk

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Lincoln Spiteri 1999-10-15 14:43:03 Re: [GENERAL] Convert MS access database into PostgreSQL
Previous Message soundar rajan 1999-10-15 14:36:07 jdbc driver problem