Re: Why does this plpgslq always return 1?

Поиск
Список
Период
Сортировка
Искать
От
Jan Wieck
Тема
Re: Why does this plpgslq always return 1?
Дата
Msg-id
200107301656.f6UGuUg07305@jupiter.us.greatbridge.com
Ответ на
Список
Дерево обсуждения
Why does this plpgslq always return 1? "John Oakes" <john@networkproductions.net>
Re: Why does this plpgslq always return 1? Stephan Szabo <sszabo@megazone23.bigpanda.com>
Re: Why does this plpgslq always return 1? Jan Wieck <JanWieck@Yahoo.com>
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@Yahoo.com #



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


В списке pgsql-sql по дате отправления
От: Chris Ruprecht
Дата:
От: Joe Conway
Дата:
FAQ