Skip site navigation (1) Skip section navigation (2)

Re: Analysis Function

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: David Jarvis <thangalin(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Analysis Function
Date: 2010-06-11 09:42:34
Message-ID: 4C12050A.5060100@enterprisedb.com (view raw or flat)
Thread:
Lists: 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

In response to

Responses

pgsql-performance by date

Next:From: Jayadevan MDate: 2010-06-11 09:56:09
Subject: Query about index usage
Previous:From: David JarvisDate: 2010-06-11 09:18:08
Subject: Re: Analysis Function

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group