pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Equality operators on NULL values
2+ messages / 2 participants
[nested] [flat]

* Equality operators on NULL values
@ 2003-08-24 01:28  Bertrand Petit <pgsql-sql@phoe.frmug.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Bertrand Petit @ 2003-08-24 01:28 UTC (permalink / raw)
  To: pgsql-sql


	(in)Equality operators evaluates to NULL when any of their
arguments are NULL as summarized bellow.

	NULL=NULL ==> NULL
	1=NULL    ==> NULL
	1=1       ==> t
	1=2       ==> f

I have a case where I need to delete rows from table A for records
that are designated in table B. One of the joined colum can have NULL
values. Therefore I need an operator behaving as follows:

	NULL=NULL ==> t
	1=NULL    ==> NULL (or anything else as long as it is not t)
	1=1       ==> t
	1=2       ==> f

I replaced the use of the = operator with this expression:

	nullif(tabA.col_with_nulls, tabB.col_with_nulls) IS NULL

It works correctly but the intent is not that clear.

	Is there a stock replacement operator that would behave like
the second truth table?

	Regards,
	Bertrand.

-- 
%!PS
297.6 420.9 translate 90 rotate 0 setgray gsave 0 1 1{pop 0 180 moveto 100
180 170 100 170 -10 curveto 180 -9 180 -9 190 -10 curveto 190 100 100 180
0 180 curveto fill 180 rotate}for grestore/Bookman-LightItalic findfont
240 scalefont setfont -151.536392 -63.7998886 moveto (bp)show showpage



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Equality operators on NULL values
@ 2003-08-24 08:43  Peter Eisentraut <peter_e@gmx.net>
  parent: Bertrand Petit <pgsql-sql@phoe.frmug.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2003-08-24 08:43 UTC (permalink / raw)
  To: Bertrand Petit <pgsql-sql@phoe.frmug.org>; +Cc: pgsql-sql

Bertrand Petit writes:

>         NULL=NULL ==> t
>         1=NULL    ==> NULL (or anything else as long as it is not t)
>         1=1       ==> t
>         1=2       ==> f

> 	Is there a stock replacement operator that would behave like
> the second truth table?

No, but why not write

(a = b) or (a is null and b is null)

-- 
Peter Eisentraut   peter_e@gmx.net




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2003-08-24 08:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-24 01:28 Equality operators on NULL values Bertrand Petit <pgsql-sql@phoe.frmug.org>
2003-08-24 08:43 ` Peter Eisentraut <peter_e@gmx.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox