plpgsql functions and NULLs - Mailing list pgsql-sql

From Don Drake
Subject plpgsql functions and NULLs
Date
Msg-id 6c21003b0501301141234c256b@mail.gmail.com
Whole thread Raw
Responses Re: plpgsql functions and NULLs
Re: plpgsql functions and NULLs
List pgsql-sql
OK, I have a function that finds records that changed in a set of
tables and attempts to insert them into a data warehouse.

There's a large outer loop of candidate rows and I inspect them to see
if the values really changed before inserting.

My problem is that when I look to see if the row exists in the
warehouse already, based on some IDs, it fails when an ID is NULL. 
The ID is nullable, so that's not a problem.

But I'm forced to write an IF statement looking for the potential NULL
and write 2 queries:

IF omcr_id is null  select * from ....  WHERE omcr_id is NULL  AND ...
ELSE   select * from ....  WHERE omcr_id=candidate.omcr_id  AND ....
END IF;

IF FOUND
...

Is there a way to do the lookup in one statement?? This could get ugly
quick.  I'm using v7.4.

Thanks.

-Don

-- 
Donald Drake
President
Drake Consulting
http://www.drakeconsult.com/
312-560-1574


pgsql-sql by date:

Previous
From: PFC
Date:
Subject: Re: plpgsql select into with multiple target variables
Next
From: Thomas F.O'Connell
Date:
Subject: Re: plpgsql functions and NULLs