Re: problem with float8 input format

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ldm(at)apartia(dot)ch
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with float8 input format
Date: 2000-08-12 16:41:10
Message-ID: 23015.966098470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Louis-David Mitterrand <cunctator(at)apartia(dot)ch> writes:
> where "date_part" comes from "date_part('epoch', stopdate)" in a
> previous query. The problem is the value of stop_date is not the number
> of seconds since the epoch but some internal representation of the data.
> So I can't compare stop_date with the output of
> GetCurrentAbsoluteTime().

GetCurrentAbsoluteTime yields an "abstime", so you should coerce the
"timestamp" result of date_part() to abstime and then you will get a
value you can compare directly.

> What function should I use to convert the Datum to a C int?
> DatumGetInt32 doesn't seem to work here.

No, because timestamps are really floats. (abstime is an int though.)

> And what is the method for float8 Datum conversion to C double?

double x = * DatumGetFloat64(datum);

This is pretty grotty because it exposes the fact that float8 datums
are pass-by-reference (ie, pointers). 7.1 will let you write

double x = DatumGetFloat8(datum);

which is much cleaner. (I am planning that on 64-bit machines it will
someday be possible for float8 and int64 to be pass-by-value, so it's
important to phase out explicit knowledge of the representation in user
functions.)

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sean Weissensee 2000-08-12 16:51:00 ClassNotFoundException
Previous Message Prasanth A. Kumar 2000-08-12 16:34:42 Re: PostgreSQL interfaces for PHP and Perl

Browse pgsql-hackers by date

  From Date Subject
Next Message Louis-David Mitterrand 2000-08-12 16:51:06 dangers of setlocale() in backend (was: problem with float8 input format)
Previous Message Tom Lane 2000-08-12 16:15:26 Re: solution! (was: Re: problem with float8 input format)