Re: When is a record NULL? - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: When is a record NULL?
Date
Msg-id 2CA937FC-2501-442E-BB3E-879D12132370@kineticode.com
Whole thread Raw
In response to Re: When is a record NULL?  ("David E. Wheeler" <david@kineticode.com>)
Responses Re: When is a record NULL?
Re: When is a record NULL?
List pgsql-hackers
On Jul 24, 2009, at 2:59 PM, David E. Wheeler wrote:

>    FETCH have INTO rec_have;
>    FETCH want INTO rec_want;
>    WHILE NOT rec_have IS NULL OR NOT rec_want IS NULL LOOP
>        IF rec_have IS DISTINCT FROM rec_want THEN
>            RETURN false;
>        END IF;
>        rownum = rownum + 1;
>        FETCH have INTO rec_have;
>        FETCH want INTO rec_want;
>    END LOOP;
>    RETURN true;

Bah. It fails to do what I want when I pass cursors that return:
        VALUES (NULL, NULL), (NULL, NULL)        VALUES (NULL, NULL)

So when it gets to that second row in the first cursor, it doesn't  
know it's a row with NULLs as opposed to an empty row. So this bit:
   WHILE NOT rec_have IS NULL OR NOT rec_want IS NULL LOOP

Obviously isn't detecting the difference. I tried
    WHILE (NOT rec_have IS NULL AND rec_have IS DISTINCT FROM NULL)       OR (NOT rec_want IS NULL AND rec_want IS
DISTINCTFROM NULL)
 

and
    WHILE (NOT rec_have IS NULL AND NOT rec_have IS NOT DISTINCT FROM  
NULL)       OR (NOT rec_want IS NULL AND NOT rec_want IS NOT DISTINCT FROM  
NULL)

But they didn't work, either.

There's got to be a way to do this; better, there ought to be an easy  
way to tell the difference. :-(

Thanks,

David


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: SE-PostgreSQL Specifications
Next
From: Tom Lane
Date:
Subject: Re: Non-blocking communication between a frontend and a backend (pqcomm)