Re: Record variable not behaving as expected (bug?)

From: "Postgres User" <postgres(dot)developer(at)gmail(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>, "Postgres User" <postgres(dot)developer(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Record variable not behaving as expected (bug?)
Date: 2007-11-30 20:34:57
Message-ID: b88c3460711301234scfff83axe222b74eebd2b56e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Sorry, here's the code:

CREATE TABLE table2 (
"s_val" NUMERIC(6,2),
"e_val" NUMERIC(6,2)
);

CREATE FUNCTION divide () RETURNS numeric AS
$body$
declare
retval numeric(6,2);
rec record;
begin
SELECT * INTO rec FROM test.table2 LIMIT 0;
rec.s_val = 100.0;
rec.e_val = 101.0;

-- returns correct value w/ casting:
--retval = ((rec.s_val::numeric(6,2) - rec.e_val::numeric(6,2)) /
rec.s_val::numeric(6,2)) * 100;

-- returns incorrect value, as if fields have invalid datatypes:
retval = ((rec.s_val - rec.e_val) / rec.s_val) * 100;

return retval;
end
$body$
LANGUAGE 'plpgsql';

On Nov 30, 2007 12:31 PM, Postgres User <postgres(dot)developer(at)gmail(dot)com> wrote:
> Sure, I'd be glad to provide any additional code or info that I can.
> This issue took me quite awhile to track down from the 200-line
> function that was breaking.
>
> When I execute the function defined above, here's the output:
>
> select divide()
> ?column?
> ------------------------
> 0
>
> > Seems rather unlikely to affect just windows. Can you post a script
> > that you can run against a blank database that shows the problem.
> > complete with output on your machine.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martin 2007-11-30 20:51:15 Re: Porting from FrontBase
Previous Message Postgres User 2007-11-30 20:31:53 Re: Record variable not behaving as expected (bug?)