Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 174C9B5DBFC for ; Mon, 20 Jun 2011 12:54:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 89521-10 for ; Mon, 20 Jun 2011 15:54:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 7C043B5DBFA for ; Mon, 20 Jun 2011 12:54:09 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p5KFs85r010355 for ; Mon, 20 Jun 2011 15:54:08 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p5KFs81o010354; Mon, 20 Jun 2011 15:54:08 GMT (envelope-from www) Date: Mon, 20 Jun 2011 15:54:08 GMT Message-Id: <201106201554.p5KFs81o010354@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6069: C function returns NaN when part of an SQL function From: "Robert Kruus" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201106/183 X-Sequence-Number: 30562 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.