X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 7578FD7A2C for ; Wed, 12 Oct 2005 04:36:51 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 73681-09 for ; Wed, 12 Oct 2005 07:36:47 +0000 (GMT) Received: from pjetlic.mobart.hr (pjetlic.mobart.hr [80.80.51.10]) by svr1.postgresql.org (Postfix) with ESMTP id 93F26D79E1 for ; Wed, 12 Oct 2005 04:36:48 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by pjetlic.mobart.hr (Postfix) with ESMTP id 7ECBC17A39; Wed, 12 Oct 2005 09:36:48 +0200 (CEST) Received: from pjetlic.mobart.hr ([127.0.0.1]) by localhost (pjetlic [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 04075-05-6; Wed, 12 Oct 2005 09:36:48 +0200 (CEST) Received: from mike.mobart.hr (mike.mobart.hr [192.168.10.94]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by pjetlic.mobart.hr (Postfix) with ESMTP id 5C6A717A37; Wed, 12 Oct 2005 09:36:48 +0200 (CEST) Subject: Re: Returning NULL results? From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: Richard Huxton Cc: pgsql-sql@postgresql.org In-Reply-To: <434BCE99.1040608@archonet.com> References: <1129040845.7911.9.camel@ekim> <434BCE99.1040608@archonet.com> Content-Type: text/plain Organization: Mob-Art Date: Wed, 12 Oct 2005 09:36:51 +0200 Message-Id: <1129102611.9305.12.camel@ekim> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by OpenSource AV+AS Mail Server X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200510/101 X-Sequence-Number: 22954 On Tue, 2005-10-11 at 15:39 +0100, Richard Huxton wrote: > Mario Splivalo wrote: > > > > Of course, if it returns no rows, I'm presented with an error, saying: > > > > ERROR: record "rec" has no field "_qv" > > > > This is logical. My question would be is there a way around this > > withouth first doing SELECT COUNT(*) FROM tmbBids WHERE ..., and then if > > COUNT(*) is zero THEN bidCount := NULL ELSE if COUNT(*) is not zero then > > do SELECT from the begining? > > Could you check the FOUND variable? As in IF NOT FOUND THEN RETURN NULL > That actually works, but it's a bit of fuss to use. I need to have it inside the FOR loop, then exit the loop if FOUND is NOT TRUE, wich makes the code even harder to read/mantain. Do you think that anytime soon would we be able to do SELECTs from the temporary tables withouth EXECing those selects? And, some qualifier for the variables (@ in T-SQL, $ in PHP, or something similair) would make the code even more readable. Just my tought. Btw, on postgres 7.4 you can do SELECT something FROM ...., and if query returns no rows, the FOR loop is skipped. So, it's safe to do something like: someVar:=NULL; _SQL:='SELECT someVar FROM someTable WHERE someCondition...' FOR rec IN EXECUTE _SQL LOOP someVar:=rec.someVar; END LOOP; Now, if select returns no rows, the LOOP/END LOOP is skippend, and someVar is se to be null before FOR. Mario -- Mario Splivalo Mob-Art mario.splivalo@mobart.hr "I can do it quick, I can do it cheap, I can do it well. Pick any two."