Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCdsO-0004AR-IH for pgsql-bugs@postgresql.org; Fri, 14 Sep 2012 21:56:40 +0000 Received: from hogranch.com ([75.101.82.47]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCdsK-00066B-Cj for pgsql-bugs@postgresql.org; Fri, 14 Sep 2012 21:56:40 +0000 Received: from [192.168.0.2] (porker [192.168.0.2]) by hogranch.com (8.11.6/8.11.6) with ESMTP id q8ELuR925945 for ; Fri, 14 Sep 2012 14:56:27 -0700 Message-ID: <5053A806.4060700@hogranch.com> Date: Fri, 14 Sep 2012 14:56:22 -0700 From: John R Pierce User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: how to proccess record returning null References: <1347563825521-5723932.post@n5.nabble.com> <505265EA.7040901@hogranch.com> <1347636697274-5724061.post@n5.nabble.com> In-Reply-To: <1347636697274-5724061.post@n5.nabble.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-HawgScanner-Information: Please contact the ISP for more information X-HawgScanner: Found to be clean X-Pg-Spam-Score: -2.4 (--) X-Archive-Number: 201209/150 X-Sequence-Number: 34145 On 09/14/12 8:31 AM, te wrote: > Sorry I didnt mention it. > > temp is a table name. > > FOR r in select distinct(id) from temp > > There are no distinct id's in table 'temp', so record 'r' has null values. > > So I guess the control is not going inside the loop. > > Any suggestions? there's a difference between zero records, and a record containing null fields.. yes, if there are no records, the loop will execute zero iterations, and result will be integer zero. as coded, for each record, it will test if id is null or an empty string, the result value will be that of the last distinct(id); since no id is likely to be null or an empty string, the odds are, it will be returning 999 if there are any records and 0 if there aren't any. what exactly do you WANT to do? -- john r pierce N 37, W 122 santa cruz ca mid-left coast