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

From Tom Lane
Subject Re: pfree() after palloc() in trigger (was: Re: understanding Datum -> char * -> Datum conversions)
Date
Msg-id 22786.959267503@sss.pgh.pa.us
Whole thread Raw
In response to pfree() after palloc() in trigger (was: Re: understanding Datum -> char * -> Datum conversions)  (Louis-David Mitterrand <cunctator@apartia.ch>)
List 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 by date:

Previous
From: Tom Lane
Date:
Subject: Re: understanding Datum -> char * -> Datum conversions
Next
From: Ed Loehr
Date:
Subject: Timezone discrepancies