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

From Louis-David Mitterrand
Subject Re: understanding Datum -> char * -> Datum conversions
Date
Msg-id 20000525124440.A11202@styx
Whole thread Raw
In response to Re: understanding Datum -> char * -> Datum conversions  (Karel Zak <zakkr@zf.jcu.cz>)
Responses Re: understanding Datum -> char * -> Datum conversions
List pgsql-hackers
On Thu, May 25, 2000 at 12:03:55PM +0200, Karel Zak wrote:
> > The problem is converting the Datum to a base C type in order to be able
> > to modify it.
> > 
> > in pgsql/contrib/spi/timetravel.c there is an example which modifies
> > date columns and uses DatumGetInt32 to convert them. But this is
> > confusing because (1) Tom Lane says that datetime columns are double and
> > one should use DatumGetPointer (how do I use the pointer after?) and (2)
> > DatumGetInt32 doesn't seem to return the number of seconds.
> 
>  See in PG's backend source files:
> 
>     c.h         - for datetype definition and Datum macros,
>               we have Datum macros for double/float types too.
>               
>     buildin.h     - for datetype conversion.
>     utils/timestamp.h   ...etc.
> 
>  and directory  utils/adt for inspiration "how work
> with pg types :-)

I'm reading these files but still got a problem:
   Datum price_datum;   float new_price;
   new_price = 10.5;   price_datum = Float32GetDatum(&new_price);
   SPI_modifytuple(relation, tupdesc, &attnum, &price_datum, NULL);

... and when I check the DB the new_price field contains a negative
number, even though elog(NOTICE, ..., new_price) displays the correct
value.

If I could just understand how to correctly insert new_price it would
really help a great deal in understanding.

Thanks again,

-- 
Louis-David Mitterrand - ldm@apartia.org - http://www.apartia.fr

There are three types of people in the world: those who can count,
and those who can't.


pgsql-hackers by date:

Previous
From: Michael Meskes
Date:
Subject: 7.0.1?
Next
From: Zeugswetter Andreas SB
Date:
Subject: AW: Berkeley DB...