Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCEuU-0008U9-Tr for pgsql-bugs@postgresql.org; Thu, 13 Sep 2012 19:17:11 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TCEuR-0002ms-Ow for pgsql-bugs@postgresql.org; Thu, 13 Sep 2012 19:17:10 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1TCEuP-0001ft-IB for pgsql-bugs@postgresql.org; Thu, 13 Sep 2012 12:17:05 -0700 Date: Thu, 13 Sep 2012 12:17:05 -0700 (PDT) From: te To: pgsql-bugs@postgresql.org Message-ID: <1347563825521-5723932.post@n5.nabble.com> Subject: how to proccess record returning null MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.5 (/) X-Archive-Number: 201209/129 X-Sequence-Number: 34124 Hi all, I am new to postgresql and I am trying to write a function which uses record (r) to select from table and then proccess that record value. CREATE OR REPLACE FUNCTION clean() RETURNS integer AS $$ DECLARE r record; result integer:= 0; BEGIN FOR r in select distinct(id) from temp loop IF r.id is null or r.id ='' THEN result := 555; else result := 999; end if; end loop; RETURN result; END; $$ LANGUAGE plpgsql; The problem here is 'r' is returning no records and I want to set result to 555 if r.id is null. The function is created successfully but the result select clean() is always '0'. I am unable to spot the problem. May be this is trivial but I am struggling for it. Can anybody suggest anything? -- View this message in context: http://postgresql.1045698.n5.nabble.com/how-to-proccess-record-returning-null-tp5723932.html Sent from the PostgreSQL - bugs mailing list archive at Nabble.com.