Re: Why does this plpgslq always return 1?

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: John Oakes <john(at)networkproductions(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Why does this plpgslq always return 1?
Date: 2001-07-30 16:56:30
Message-ID: 200107301656.f6UGuUg07305@jupiter.us.greatbridge.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Stephan Szabo wrote:
> 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;

And check for zero before doing a division, as a transaction
abort is usually not exactly what you want.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gonzo Rock 2001-07-30 17:39:45 Re: Date Time Functions - ANSI SQL ?
Previous Message Joe Conway 2001-07-30 16:43:09 Re: Big table - using wrong index - why?