Re: Why does this plpgslq always return 1? - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: Why does this plpgslq always return 1?
Date
Msg-id Pine.BSF.4.21.0107272043550.84804-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Why does this plpgslq always return 1?  ("John Oakes" <john@networkproductions.net>)
Responses Re: Why does this plpgslq always return 1?  (Jan Wieck <JanWieck@Yahoo.com>)
List 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';



pgsql-sql by date:

Previous
From: Joel Burton
Date:
Subject: RE: Database Design Question
Next
From: María Elena Hernández
Date:
Subject: Get name of columns in a table