From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Using null or not null in function arguments |
Date: | 2009-01-23 15:53:46 |
Message-ID: | 20090123155346.GN3008@frubble.xen.chris-lamb.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Fri, Jan 23, 2009 at 06:32:17PM +0300, Igor Katson wrote:
> Sam, I'm not sure if this is correct to do that, as you I don't want to
> remember what will happen, if you use NULL = NULL or upper(NULL) etc.:
>
> WHERE
> COALESCE(city_id = i_city_id, TRUE) AND
> COALESCE(edu_id = i_edu_id, TRUE) AND
> COALESCE(upper(firstname) ~ upper(i_firstname), TRUE) AND
> COALESCE(upper(lastname) ~ upper(i_lastname), TRUE)
I'm not quite sure what you mean when you say "I don't want to remember
what will happen". Here is a state table of the various options you've
presented:
param tbl Sam's Your's/Michael's
NULL NULL TRUE NULL
NULL 0 TRUE TRUE
NULL 1 TRUE TRUE
0 NULL TRUE NULL
0 0 TRUE TRUE
0 1 FALSE FALSE
1 NULL TRUE NULL
1 0 FALSE FALSE
1 1 TRUE TRUE
The "tbl" column is the value for, say, edu_id; the "param" is the
matching parameter value, say i_edu_id. "Sam's" is the output of doing a
COALESCE and the "Your's/Michael's" column is the output of doing your
original CASE statement or Michael's OR variant. The thing to note are
the extra NULLs in your variant as these will cause any row with a NULL
value in the table to never get returned. This may, or may not, be what
you want!
--
Sam http://samason.me.uk/
From | Date | Subject | |
---|---|---|---|
Next Message | decibel | 2009-01-23 16:18:30 | Re: deductive databases in postgreSQL |
Previous Message | Igor Katson | 2009-01-23 15:48:07 | Storing a result of a select in a variable |