Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dIb11-0003bV-1a for pgsql-sql@arkaria.postgresql.org; Wed, 07 Jun 2017 13:28:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dIb10-0004q5-HS for pgsql-sql@arkaria.postgresql.org; Wed, 07 Jun 2017 13:28:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dIb0y-0004n7-In for pgsql-sql@postgresql.org; Wed, 07 Jun 2017 13:28:48 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dIb0v-0004DV-Th for pgsql-sql@postgresql.org; Wed, 07 Jun 2017 13:28:48 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 951A320860; Wed, 7 Jun 2017 09:28:44 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 07 Jun 2017 09:28:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=2dB19tviJk9PHTpgZw v+8qbUHoW65HDDEotiRskUgaY=; b=UDAzFI2e5nQ3IGlKt4v2oxDqGs2sn4Dq8K P8WDAuaZGV93JpmfHtbOpK00dRtPTM4b5cfQRwxF9Wz/tp5MlEfUj6Be9xugt8Ky +4Ueo8QV7c+hRm1gxsuRtMuKdDjl92zwn8zmAc9y5UIDIS7YkL6uhHxooM7Ky/EJ qXcqV9ntvXvamGqy3u6Js4qqs+FzeIegyi8s1P4c1Kd7Yli9cDaxyJQ4srsW6Kpu y478zwO8wmRHePUly5Bw0wBOOa5PHuBCkSBfd0MPb4VBCeBPoDGlHZbYRLtGPXvP 1YlWDf6GpmFuoFyt8n354a2L3iJ+yYPZtPWtOCyi+fl8HizK4eEg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=2dB19tviJk9PHTpgZwv+8qbUHoW65HDDEotiRskUgaY=; b=go6BxJmd /4g/fFRggq1dkoJWJfNta+Ma4SrSVHBUcPUCs/Rd6oNFCUoRi2Wh56utKTaZdjJJ 4vixhtkaAQcJKwhbpcVG2l5uInuwLmdaUwWrJo+SPE7Te4VjhiR7rVIk6DEYt7bq bN8/f+3uK3vVJ49kvJCP4+NNuN62NJ8CPZU7/XoF3DoYzpIuQc7y1Kr+8UfQr5gZ Kpke4mpygZrkuBQAmYLjNZfCQ4oUXE2pQlAEAPAI+wp2HEQCDgC6bfJerFNG2/IN uYecYTwOpn17VqNMKmSuXMqVGsKM2Sj3ox4BGGzTbPb9BLJqN6qdimRzM5k++owz 7qiuyJq0a1zTuA== X-ME-Sender: X-Sasl-enc: aYvePXTOIt0FGsEuAMFbifDqgC18ZvwYGhqCWr5d6J8N 1496842124 Received: from [192.168.1.2] (75-172-126-41.tukw.qwest.net [75.172.126.41]) by mail.messagingengine.com (Postfix) with ESMTPA id 0F90124922; Wed, 7 Jun 2017 09:28:43 -0400 (EDT) Subject: Re: Not getting the expected results for a simple where not in To: Jonathan Moules , pgsql-sql@postgresql.org References: <15c827e9305.ae02346553193.1322341002046903374@lightpear.com> From: Adrian Klaver Message-ID: Date: Wed, 7 Jun 2017 06:28:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <15c827e9305.ae02346553193.1322341002046903374@lightpear.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 06/07/2017 05:20 AM, Jonathan Moules wrote: > Hi List, > I'm a little confused by what seems like it should be a simple query and > was hoping someone could explain what's going on. > Using PG 9.4.x > > It seems to relate to the nulls. If I change the above and add "and str > is not null" into the subquery: > > select > * > from > aaa.testing_nulls > where > str not in > ( > select > str > from > aaa.testing_nulls > where > status in ('aa') > and str is not null > ) > > It now gives the expected results. Or you could do: select * from testing_nulls where str not in ( select coalesce(str, '') from testing_nulls where status in ('aa') ) ; str | status --------+-------- third | NULL fourth | bb (2 rows) > Why is this? > (I tested this in SQLite too, and get the same behaviour, so I guess > it's a generic SQL thing I've never encountered before.) > Thanks, > Jonathan -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql