Received: from smtp011.mail.yahoo.com (smtp011.mail.yahoo.com [216.136.173.31]) by postgresql.org (8.11.3/8.11.1) with SMTP id f6UGmff26053 for ; Mon, 30 Jul 2001 12:48:41 -0400 (EDT) (envelope-from janwieck@yahoo.com) Received: from jupiter.us.greatbridge.com (65.196.69.55) by smtp.mail.vip.sc5.yahoo.com with SMTP; 30 Jul 2001 16:48:40 -0000 X-Apparently-From: Received: (from wieck@localhost) by jupiter.us.greatbridge.com (8.11.2/8.11.2) id f6UGuUg07305; Mon, 30 Jul 2001 12:56:30 -0400 From: Jan Wieck Message-Id: <200107301656.f6UGuUg07305@jupiter.us.greatbridge.com> Subject: Re: Why does this plpgslq always return 1? In-Reply-To: from Stephan Szabo at "Jul 27, 2001 08:48:44 pm" To: Stephan Szabo Date: Mon, 30 Jul 2001 12:56:30 -0400 (EDT) CC: John Oakes , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL68 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200107/381 X-Sequence-Number: 4195 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