Jean-Christian Imbeault wrote:
> I have created a pgpsql function but it does not return the expected
> value. It's a simple sql query, and if I do the same query by hand I get
> the expected result so I can't see what is wrong.
> create or replace function member_points_to_be_refunded(integer) returns
> integer as '
> declare points_used integer := 0;
> begin
> SELECT into points_used sum(points_used)
You are using the same name for the local variable inside the function
as the column name, therefore you are actually summing the local variable.
Use a different name, or qualify the column name i.e.
sum(invoices.points_used)
--
Peter Gibbs
EmKel Systems