Re: custom C function problem
От | Dan \"Heron\" Myers |
---|---|
Тема | Re: custom C function problem |
Дата | |
Msg-id | 481CA7D1.6040101@xnapid.com обсуждение исходный текст |
Ответ на | Re: custom C function problem (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: custom C function problem
|
Список | pgsql-general |
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 documentation: 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 crashing. For example: SELECT copytext(calling_party) FROM event; crashes. - Dan
В списке pgsql-general по дате отправления: