BUG #6069: C function returns NaN when part of an SQL function

From: "Robert Kruus" <robert(dot)kruus(at)gov(dot)sk(dot)ca>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #6069: C function returns NaN when part of an SQL function
Date: 2011-06-20 15:54:08
Message-ID: 201106201554.p5KFs81o010354@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 6069
Logged by: Robert Kruus
Email address: robert(dot)kruus(at)gov(dot)sk(dot)ca
PostgreSQL version: 9.0.4
Operating system: FreeBSD 8.1 64 Bit
Description: C function returns NaN when part of an SQL function
Details:

I have a c function in an external lib that have written and when called on
its own it works as expected:

SELECT dmc(13.433, 16.1, 9, 9.6, 21.59, 6);
dmc
-------------------
0.316972255706787

But if I include it as part of an SQL function which returns a custom type:

SELECT * FROM fwi_all(22.63, 13.433, 148.451, 62.34, 16.1, 93, 9.6, 21.59,
6);
ffmc | dmc | dc | isi | bui |
fwi | sdmc
------------------+-----+------------------+----------------------+-----+---
--+------------------
12.9909820556641 | NaN | 109.883583068848 | 1.83133633981925e-05 | NaN |
NaN | 28.2005863189697

CREATE OR REPLACE FUNCTION fwi_all(old_ffmc FLOAT, old_dmc FLOAT, old_dc
FLOAT, sdmc_old FLOAT, "temp" FLOAT, rh FLOAT, wind FLOAT, rain FLOAT, month
INTEGER)
RETURNS fwi AS
$BODY$
SELECT ffmc, dmc, dc, isi, bui, fwi(isi, bui), sdmc FROM (SELECT s1.*,
isi(s1.ffmc, $8), bui(s1.dmc, s1.dc) FROM (SELECT ffmc($1, $5, $6, $7, $8),
dmc($2, $5, $6, $7, $8, $9), dc($3, $5, $6, $7, $8, $9), sdmc($4, $5, $6,
$7, $8, $9)) s1) s2
$BODY$
LANGUAGE 'sql' STABLE;

The dmc function returns a double, and the custom type consists of doubles
as well.

I initially noticed the error as the fwi type was returning a set of real
and I thought it may have been due type casting.
Adding explicit type casting throughout does not change the result.

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2011-06-20 20:16:04 Re: BUG #6066: Bad string in German translation causes segfault (user-triggerable)
Previous Message Ana Ramirez 2011-06-20 15:08:12 Re: [pgsql-es-ayuda] Re: [pgsql-es-ayuda] Re: [BUGS] ¿Está el servidor en ejecución localmente y aceptando conexiones en el socket de dominio Unix <</tmp/.s.PGSQL.5432>>?