Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > Re: custom C fu...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 15444 of 17602
Post > Topic >>

Re: custom C function problem

by heron@[EMAIL PROTECTED] ("Dan \"Heron\" Myers") May 3, 2008 at 11:58 AM

Tom Lane wrote:
> What cases have you gotten to work correctly?
> 
> My guess is that you're either messed up about V0 vs V1 calling
> convention (ie you forgot PG_FUNCTION_INFO_V1, or added it when you
> shouldn't have), or you've got some kind of problem with not detoasting
> toasted input values.  There's not enough info here to venture more.
> 
> 			regards, tom lane

This one works correctly:

PG_FUNCTION_INFO_V1(event_duration);

Datum
event_duration(PG_FUNCTION_ARGS)
{
     int32 state = PG_GETARG_INT32(0);
     int32 target = PG_GETARG_INT32(1);
     int32 event = PG_GETARG_INT32(2);
     Timestamp start = PG_GETARG_TIMESTAMP(3);
     Timestamp end = PG_GETARG_TIMESTAMP(4);

     //If this event is the correct type we need to add the event time 
to the total event time (state)
     if(target == event){
     	state += (end - start);
     }

     PG_RETURN_INT32(state);
}

I can use event_duration in this query without problems:

SELECT call_id, event_duration(4,event_type,start_time,end_time) AS 
talking_duration FROM event GROUP BY call_id;

One case that fails is essentially copied from the V1 section in the 
do***entation:

PG_FUNCTION_INFO_V1(copytext);

Datum copytext(PG_FUNCTION_ARGS)
{
     text* t = PG_GETARG_TEXT_P(0);
     text* new_t = (text *) palloc(VARSIZE(t));
     SET_VARSIZE(new_t, VARSIZE(t));

     memcpy((void *) VARDATA(new_t), (void *) VARDATA(t),
            VARSIZE(t) - VARHDRSZ);
     PG_RETURN_TEXT_P(new_t);
}

Attempting to use copytext in a query results in Postgres cra****ng.
For example:

SELECT copytext(calling_party) FROM event;

crashes.

- Dan

-- 
Sent via pgsql-general mailing list (pgsql-general@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
 




 6 Posts in Topic:
custom C function problem
heron@[EMAIL PROTECTED]   2008-05-03 11:27:36 
Re: custom C function problem
tgl@[EMAIL PROTECTED] (T  2008-05-03 13:50:35 
Re: custom C function problem
heron@[EMAIL PROTECTED]   2008-05-03 11:58:41 
Re: custom C function problem
tgl@[EMAIL PROTECTED] (T  2008-05-03 15:46:46 
Re: custom C function problem
heron@[EMAIL PROTECTED]   2008-05-03 18:20:50 
Re: custom C function problem
tgl@[EMAIL PROTECTED] (T  2008-05-03 21:04:13 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 19:16:21 CST 2008.