Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

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);

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

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.

pgsql-bugs by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group