pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Wieck <JanWieck@Yahoo.com>
To: Stephan Szabo <sszabo@megazone23.bigpanda.com>
Cc: John Oakes <john@networkproductions.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: Why does this plpgslq always return 1?
Date: Mon, 30 Jul 2001 12:56:30 -0400 (EDT)
Message-ID: <200107301656.f6UGuUg07305@jupiter.us.greatbridge.com> (raw)
In-Reply-To: <Pine.BSF.4.21.0107272043550.84804-100000@megazone23.bigpanda.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




view thread (3+ messages)

Message-ID: <200107301656.f6UGuUg07305@jupiter.us.greatbridge.com>
Permalink:  ../200107301656.f6UGuUg07305@jupiter.us.greatbridge.com/
Also on:    postgresql.org/message-id/200107301656.f6UGuUg07305@jupiter.us.greatbridge.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: JanWieck@Yahoo.com, sszabo@megazone23.bigpanda.com, john@networkproductions.net
  Subject: Re: Why does this plpgslq always return 1?
  In-Reply-To: <200107301656.f6UGuUg07305@jupiter.us.greatbridge.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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