Re: SET within a function? - Mailing list pgsql-general

From Arthur Ward
Subject Re: SET within a function?
Date
Msg-id 1732.192.168.0.101.1066149839.squirrel@192.168.0.2
Whole thread Raw
In response to Re: SET within a function?  (Edmund Dengler <edmundd@eSentire.com>)
Responses Re: SET within a function?
List pgsql-general
> Is the rewrite only for the literal 'X = NULL' or will it do a test
> against a value such as 'X = OLD.X' (and rewrite is OLD.X is NULL)?
>
> Is there any way to match NULLS to each other (as I am looking for a
> literal row, not using NULL as the UNKNOWN). I suppose I could put in a
> dummy value for the 'Not a valid value', but it seems to be quite awkward
> when I really do want the NULL.

I ended up writing an "equivalent" function for the project I'm working
on. It goes like this in plpgsql:

    IF $1 IS NULL THEN
        RETURN $2 IS NULL;
    ELSIF $2 IS NULL THEN
        -- We already know $1 is not null.
        RETURN FALSE;
    ELSE
        -- Both args are not null.
        RETURN $1 = $2;
    END IF;

That's the basic idea. I put a wrapper around this to generate a copy of
it for all the data types used in my database.

pgsql-general by date:

Previous
From: Ed Loehr
Date:
Subject: Re: backend exit mystery
Next
From: Edmund Dengler
Date:
Subject: Re: SET within a function?