Re: PGSQL function question

From: "Peter Gibbs" <peter(at)emkel(dot)co(dot)za>
To: "Jean-Christian Imbeault" <jc(at)mega-bucks(dot)co(dot)jp>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: PGSQL function question
Date: 2003-02-27 14:13:16
Message-ID: 017801c2de6a$5f1c8740$0b01010a@emkel.co.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Schapachnik 2003-02-27 14:29:59 Unable to delete row on 7.3.2 with schemas
Previous Message Darko Prenosil 2003-02-27 14:05:59 Re: Function example returning more then 1 value