pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Kruus <robert.kruus@gov.sk.ca>
To: pgsql-bugs@postgresql.org
Subject: BUG #6069: C function returns NaN when part of an SQL function
Date: Mon, 20 Jun 2011 15:54:08 GMT
Message-ID: <201106201554.p5KFs81o010354@wwwmaster.postgresql.org> (raw)


The following bug has been logged online:

Bug reference:      6069
Logged by:          Robert Kruus
Email address:      robert.kruus@gov.sk.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.



view thread (2+ messages)  latest in thread

Message-ID: <201106201554.p5KFs81o010354@wwwmaster.postgresql.org>
Permalink:  ../201106201554.p5KFs81o010354@wwwmaster.postgresql.org/
Also on:    postgresql.org/message-id/201106201554.p5KFs81o010354@wwwmaster.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: robert.kruus@gov.sk.ca
  Subject: Re: BUG #6069: C function returns NaN when part of an SQL function
  In-Reply-To: <201106201554.p5KFs81o010354@wwwmaster.postgresql.org>
  References: <201106201554.p5KFs81o010354@wwwmaster.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox