Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 1153C1975915 for ; Wed, 20 Jun 2012 21:16:41 -0300 (ADT) Received: from smtp-out-01.xnet.hr ([83.139.103.71] helo=smtp.xnet.hr) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ShV4i-0007bZ-56 for pgsql-bugs@postgresql.org; Thu, 21 Jun 2012 00:16:41 +0000 Received: from ike.bnet.hr (ike.bnet.hr [83.139.80.4]) by smtp.xnet.hr (XnetMailOut) with ESMTP id CD096486C8; Thu, 21 Jun 2012 02:16:24 +0200 (CEST) Received: from smtp.xnet.hr ([83.139.103.74]) by ike.bnet.hr (avcleaner-b.mx.xnet.hr [83.139.80.4]) (XNet AV Scanner, port 10026) with ESMTP id v1zWYUWRAs77; Thu, 21 Jun 2012 02:16:20 +0200 (CEST) Received: from [109.60.100.101] (unknown [109.60.100.101]) by smtp.xnet.hr (XnetMailOut) with ESMTP id BCAE08A0EE; Thu, 21 Jun 2012 02:16:20 +0200 (CEST) Message-ID: <4FE267D7.9080202@zg.htnet.hr> Date: Thu, 21 Jun 2012 02:16:23 +0200 From: Rikard Pavelic User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6701: IS NOT NULL doesn't work on complex composites References: <2782.1340219454@sss.pgh.pa.us> In-Reply-To: <2782.1340219454@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/180 X-Sequence-Number: 33407 On 20.6.2012. 21:10, Tom Lane wrote: > rikard.pavelic@zg.htnet.hr writes: >> create type t AS (i int); create type complex as (t t, i int); create table bad(i int, c complex); --This doesn't work as expected select * from bad where c is not null; > What do you consider to be "expected"? Have you read the documentation where it points out that IS NULL and IS NOT NULL are not inverses for composite values? > http://www.postgresql.org/docs/9.1/static/functions-comparison.html (I'm not that thrilled with this behavior either, but it is per SQL standard AFAICT.) regards, tom lane I understand the concept behind if one composite property is null then then IS NULL check returns NULL (instead true or false). I can even understand IS NULL check returning false. I can use ::text to get what I expected, but Postgres still seems inconsistent in handling NULL checks. create type complex as (i int, j int); create table t (i int, c complex not null); --error as expected insert into t values(1, null); --unexpected - passed!? insert into t values(1, (null,4)); -- this is false - I think it would be better if it's null, but lets move on select (null, 4) is not null --lets try again with check constraint alter table t add check(c is not null); --error as expected from is not null check above insert into t values(1, (null,4)); It seems that check constraint behaves differently. Docs say: (http://www.postgresql.org/docs/9.1/static/ddl-constraints.html) "A not-null constraint is functionally equivalent to creating a check constraint CHECK (column_name IS NOT NULL)" And at least there is more notes required ;( Let's try some more. create table x (i int, c complex); insert into x values(1,null); insert into x values(2,(1,null)); insert into x values(3,(1,2)); --first row - ok select * from x where c is null; --last row - ok select * from x where c is not null; --unexpected result again select c is null from x; I must admit I was expecting true null false Regards, Rikard