how to proccess record returning null - Mailing list pgsql-bugs

From te
Subject how to proccess record returning null
Date
Msg-id 1347563825521-5723932.post@n5.nabble.com
Whole thread Raw
Responses Re: how to proccess record returning null  (John R Pierce <pierce@hogranch.com>)
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #7516: PL/Perl crash
Next
From: John R Pierce
Date:
Subject: Re: how to proccess record returning null