Re: pfree() after palloc() in trigger (was: Re: understanding Datum -> char * -> Datum conversions)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: pfree() after palloc() in trigger (was: Re: understanding Datum -> char * -> Datum conversions)
Дата
Msg-id 22786.959267503@sss.pgh.pa.us
обсуждение исходный текст
Ответ на pfree() after palloc() in trigger (was: Re: understanding Datum -> char * -> Datum conversions)  (Louis-David Mitterrand <cunctator@apartia.ch>)
Список pgsql-hackers
Louis-David Mitterrand <cunctator@apartia.ch> writes:
> Can I do                                
>     double result = 10.5; /* for example */
>     SPI_modifytuple(relation, tupdesc, &attnum,Float32GetDatum(&result),NULL);
>                                                               ^^^

I think you could get away with that in this example.  The critical
question of course is whether the Datum pointer will continue to
be used after your routine exits.  But SPI_modifytuple should have
created the new tuple (and copied the values of pass-by-reference
items, such as float8s, into it) before returning.

BTW you should be using Float64GetDatum.  There's no real difference
in those two macros at the moment, but it's a type error that might
bite you someday (like as soon as you need to convert this code to
the new fmgr ;-)).
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: understanding Datum -> char * -> Datum conversions
Следующее
От: Ed Loehr
Дата:
Сообщение: Timezone discrepancies