Re: [GENERAL] problem with float8 input format
Louis-David Mitterrand <[EMAIL PROTECTED]> 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
[GENERAL] problem with float8 input format
Hello, Suddenly I am getting errors with the following function: SELECT incr(max_price($1),0.05) 000810.17:20:41.181 [2246] ERROR: Bad float8 input format '0.05' 000810.17:20:41.181 [2246] AbortCurrentTransaction Where incr() is defined as: CREATE FUNCTION "incr" (float8,float8 ) RETURNS float8 AS ' SELECT CASE WHEN $1 < dpow(10,int8(log($1))+1)/2 THEN (dpow(10,int8(log($1 * $2 ELSE (dpow(10,int8(log($1))+1)/2) * $2 END ' LANGUAGE 'SQL'; Strangely engough the function call works fine when called from psql but fails (but not always!) from a C trigger. Thanks in advance for any help, -- Louis-David Mitterrand - [EMAIL PROTECTED] - http://www.apartia.org "Kill a man, and you are an assassin. Kill millions of men, and you are a conqueror. Kill everyone, and you are a god." -- Jean Rostand