pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
nullif  BUG???
3+ messages / 3 participants
[nested] [flat]

* nullif  BUG???
@ 2001-07-27 09:48  guard <guard@ficnet.net>
  0 siblings, 1 reply; 3+ messages in thread

From: guard @ 2001-07-27 09:48 UTC (permalink / raw)
  To: pgsql-sql

I try

> select nullif(NULL,5)

+--------+
| case   |
+--------+
| <Null> |
+--------+



--






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

* Re: nullif  BUG???
@ 2001-07-27 15:19  Josh Berkus <josh@agliodbs.com>
  parent: guard <guard@ficnet.net>
  0 siblings, 1 reply; 3+ messages in thread

From: Josh Berkus @ 2001-07-27 15:19 UTC (permalink / raw)
  To: guard <guard@ficnet.net>; pgsql-sql

Guard, 

> > select nullif(NULL,5)
> 
> +--------+
> | case   |
> +--------+
> | <Null> |
> +--------+
> 

Er... what were you expecting, exactly?

Except for IS NULL (and COALESCE, which uses IS NULL) any operation
involving a NULL is also NULL.

-Josh


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco







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

* Re: nullif BUG???
@ 2001-07-29 03:15  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Josh Berkus <josh@agliodbs.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-07-29 03:15 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; +Cc: guard <guard@ficnet.net>; pgsql-sql

"Josh Berkus" <josh@agliodbs.com> writes:
> Er... what were you expecting, exactly?

AFAICT, the quoted behavior is correct per the defined behavior of
nullif(), cf 
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/functions-conditional.html

	NULLIF(value1, value2)

	The NULLIF function returns NULL if and only if value1 and
	value2 are equal. Otherwise it returns value1.

> Except for IS NULL (and COALESCE, which uses IS NULL) any operation
> involving a NULL is also NULL.

Well, that's not quite the correct reasoning.

NULLIF and COALESCE are both shorthands for CASE expressions, and hence
are capable of returning non-NULL for a NULL input.  It all depends on
how the CASE tests are phrased.  NULLIF is essentially
	CASE WHEN value1 = value2 THEN NULL ELSE value1 END
In the quoted example, "NULL = 5" will yield NULL, which is interpreted
as a FALSE case test, so you get the ELSE case, ie value1, ie NULL.

			regards, tom lane



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


end of thread, other threads:[~2001-07-29 03:15 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-07-27 09:48 nullif  BUG??? guard <guard@ficnet.net>
2001-07-27 15:19 ` Josh Berkus <josh@agliodbs.com>
2001-07-29 03:15   ` Re: nullif BUG??? Tom Lane <tgl@sss.pgh.pa.us>

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