Returning NULL results? - Mailing list pgsql-sql

From Mario Splivalo
Subject Returning NULL results?
Date
Msg-id 1129040845.7911.9.camel@ekim
Whole thread Raw
Responses Re: Returning NULL results?  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
_SQL := 'SELECT TmessageId FROM tmpBids WHERE TphoneNumber = ' || quote_literal(phoneNumber) || ' AND Tbid = ' ||
aBid;
FOR rec IN EXECUTE _SQL LOOP bidCount := rec._qv; END LOOP;

This works ok as long as the SELECT query returns rows. Of course, if it
returns multiple rows bidCount variable will hold just the last row
value, but the design of application is like that so the query from the
start returns only one row, or returns no rows.

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?
Mike
-- 
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."




pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Difference from average
Next
From: Tom Lane
Date:
Subject: Re: ichar