Re: Why does this plpgslq always return 1?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: John Oakes <john(at)networkproductions(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Why does this plpgslq always return 1?
Date: 2001-07-28 03:48:44
Message-ID: Pine.BSF.4.21.0107272043550.84804-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 27 Jul 2001, John Oakes wrote:

> Can anyone tell me why this always return 1? Thanks!
>
> CREATE FUNCTION passrate(date, date, text) RETURNS float AS '
>
> DECLARE
> begindate ALIAS FOR $1;
> enddate ALIAS FOR $2;
> passfail ALIAS FOR $3;
> ret float;
> countp float;
> counttotal float;
>
>
> BEGIN
>
> SELECT INTO countp COUNT(*)
> FROM benchmark
> WHERE passfail = passfail;

Ehhh? Were you expecting that to substitue
for *one* of those passfails and not the
other? ;)

Rename the alias variable to something else.

>
> SELECT INTO counttotal COUNT(*)
> FROM benchmark;
>
> ret := countp / counttotal;
> RETURN ret;
> END;'
> LANGUAGE 'plpgsql';

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Burton 2001-07-28 14:31:32 Re: Get name of columns in a table
Previous Message Joel Burton 2001-07-28 03:22:50 RE: Database Design Question