Re: understanding Datum -> char * -> Datum conversions

From: Louis-David Mitterrand <cunctator(at)apartia(dot)ch>
To: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: understanding Datum -> char * -> Datum conversions
Date: 2000-05-25 10:44:40
Message-ID: 20000525124440.A11202@styx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)apartia(dot)org - http://www.apartia.fr

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Karel Zak 2000-05-25 10:51:52 Re: understanding Datum -> char * -> Datum conversions
Previous Message Zeugswetter Andreas SB 2000-05-25 10:29:41 AW: AW: SQL3 UNDER