Re: PGSQL function question - Mailing list pgsql-general

From Peter Gibbs
Subject Re: PGSQL function question
Date
Msg-id 017801c2de6a$5f1c8740$0b01010a@emkel.co.za
Whole thread Raw
In response to PGSQL function question  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List pgsql-general
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


pgsql-general by date:

Previous
From: "Matthew Nuzum"
Date:
Subject: selective copy
Next
From: Antti Haapala
Date:
Subject: Re: SETOF (was: Function example returning more then 1