Re: understanding Datum -> char * -> Datum conversions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: understanding Datum -> char * -> Datum conversions
Date
Msg-id 9050.959205237@sss.pgh.pa.us
Whole thread Raw
In response to understanding Datum -> char * -> Datum conversions  (Louis-David Mitterrand <cunctator@apartia.ch>)
Responses Re: understanding Datum -> char * -> Datum conversions  (Brook Milligan <brook@biology.nmsu.edu>)
Re: understanding Datum -> char * -> Datum conversions  (Louis-David Mitterrand <cunctator@apartia.ch>)
List pgsql-hackers
Louis-David Mitterrand <cunctator@apartia.ch> writes:
> What I am trying to do for instance is:
> - read a ::text colum with SPI_getbinval(),
> - convert it to a char*,
> - modify it,
> - convert it back to a Datum,
> - reinsert it into the tuple through SPI_modifytuple,

> The conversions involve some pointer magic and casting that I really
> don't grasp.

Casting doesn't do it.  Use text_out() to produce a null-terminated C
string from a text Datum, and use text_in() to create a new text Datum
after you've modified the string.

> Also I am trying to read a timestamp with SPI_getbinval and get the
> number of seconds contained. Using DatumGetInt32 doens't seem to do it.

Timestamp is a double not an int ... and the datum is actually a pointer
to it.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: setproctitle()
Next
From: Peter Eisentraut
Date:
Subject: Re: Solaris 2.6 problems