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

From: Louis-David Mitterrand <cunctator(at)apartia(dot)ch>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: understanding Datum -> char * -> Datum conversions
Date: 2000-05-25 09:40:56
Message-ID: 20000525114056.A10653@styx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, May 24, 2000 at 05:53:57PM -0400, Tom Lane wrote:
> Louis-David Mitterrand <cunctator(at)apartia(dot)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.

I can't find these functions anywhere in the included .h files. Where
should I look?

> > 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.

But for example I am trying to read the result from a "SELECT
date_part('epoch', now())" which returns a number of seconds since the
epoch and I can't find a way to obtain that value through SPI_getbinval,
I have to retrieve it through SPI_getvalue and use atoi() to convert it.
I'd rather access directly the native type instead.

Which DatumGet* function should I use there?

Thanks,

--
Louis-David Mitterrand - ldm(at)apartia(dot)org - http://www.apartia.fr

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zeugswetter Andreas SB 2000-05-25 09:44:24 AW: SQL3 UNDER
Previous Message Hannu Krosing 2000-05-25 09:12:21 Re: AW: SQL3 UNDER