Re: Analysis Function - Mailing list pgsql-performance

From Heikki Linnakangas
Subject Re: Analysis Function
Date
Msg-id 4C12050A.5060100@enterprisedb.com
Whole thread Raw
In response to Re: Analysis Function  (David Jarvis <thangalin@gmail.com>)
Responses Query about index usage  (Jayadevan M <Jayadevan.Maymala@ibsplc.com>)
List pgsql-performance
On 11/06/10 11:25, David Jarvis wrote:
> Datum dateserial (PG_FUNCTION_ARGS) {
>    int32 p_year = PG_GETARG_INT32(0);
>    int32 p_month = PG_GETARG_INT32(1);
>    int32 p_day = PG_GETARG_INT32(2);
>
>    DateADT d = date2j (p_year, p_month, p_day) - POSTGRES_EPOCH_JDATE;
>    PG_RETURN_DATEADT(d);
> }
>
> Compiles without errors or warnings. The function is integrated as follows:
>
> CREATE OR REPLACE FUNCTION dateserial(integer, integer, integer)
>    RETURNS text AS
> 'ymd.so', 'dateserial'
>    LANGUAGE 'c' IMMUTABLE STRICT
>    COST 1;
>
> However, when I try to use it, the database segfaults:
>
> select dateserial( 2007, 1, 3 )
>
> Any ideas why?

The C function returns a DateADT, which is a typedef for int32, but the
CREATE FUNCTION statement claims that it returns 'text'.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

pgsql-performance by date:

Previous
From: David Jarvis
Date:
Subject: Re: Analysis Function
Next
From: Jayadevan M
Date:
Subject: Query about index usage