pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Why does this plpgslq always return 1?
3+ messages / 3 participants
[nested] [flat]

* Why does this plpgslq always return 1?
@ 2001-07-28 03:00 John Oakes <john@networkproductions.net>
  2001-07-28 03:48 ` Re: Why does this plpgslq always return 1? Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 1 reply; 3+ messages in thread

From: John Oakes @ 2001-07-28 03:00 UTC (permalink / raw)
  To: pgsql-sql

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;

 SELECT INTO counttotal COUNT(*)
 FROM benchmark;

 ret := countp / counttotal;
 RETURN ret;
END;'
LANGUAGE 'plpgsql';


John




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Why does this plpgslq always return 1?
  2001-07-28 03:00 Why does this plpgslq always return 1? John Oakes <john@networkproductions.net>
@ 2001-07-28 03:48 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  2001-07-30 16:56   ` Re: Why does this plpgslq always return 1? Jan Wieck <JanWieck@Yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Stephan Szabo @ 2001-07-28 03:48 UTC (permalink / raw)
  To: John Oakes <john@networkproductions.net>; +Cc: 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';




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Why does this plpgslq always return 1?
  2001-07-28 03:00 Why does this plpgslq always return 1? John Oakes <john@networkproductions.net>
  2001-07-28 03:48 ` Re: Why does this plpgslq always return 1? Stephan Szabo <sszabo@megazone23.bigpanda.com>
@ 2001-07-30 16:56   ` Jan Wieck <JanWieck@Yahoo.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jan Wieck @ 2001-07-30 16:56 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: John Oakes <john@networkproductions.net>; 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@Yahoo.com #



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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-07-30 16:56 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-07-28 03:00 Why does this plpgslq always return 1? John Oakes <john@networkproductions.net>
2001-07-28 03:48 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-07-30 16:56   ` Jan Wieck <JanWieck@Yahoo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox