Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 408C7632AF9 for ; Mon, 27 Apr 2009 05:54:16 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34939-05 for ; Mon, 27 Apr 2009 05:54:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from titania.wxnz.net (titania.wxnz.net [58.28.4.13]) by mail.postgresql.org (Postfix) with ESMTP id 0CFA3632991 for ; Mon, 27 Apr 2009 05:54:13 -0300 (ADT) Received: from gonzo (ip-118-90-140-242.xdsl.xnet.co.nz [118.90.140.242]) by titania.wxnz.net (Postfix) with ESMTP id F1DC21DB8379 for ; Mon, 27 Apr 2009 20:54:07 +1200 (NZST) Received: from news by gonzo with local (Exim 4.69) (envelope-from ) id 1LyMb0-00044m-1r for pgsql-sql@postgresql.org; Mon, 27 Apr 2009 20:53:50 +1200 To: pgsql-sql@postgresql.org Path: not-for-mail From: Jasen Betts Newsgroups: gmane.comp.db.postgresql.sql Subject: Re: varchar value comparisons not working? Date: 27 Apr 2009 08:53:49 GMT Organization: Dis (not Dat) Organisation Lines: 53 Message-ID: References: <1240581570.21067.18.camel@shop.telecom.co.washoe.nv.us> NNTP-Posting-Host: localhost Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: reversiblemaps.ath.cx 1240822429 15574 127.0.0.1 (27 Apr 2009 08:53:49 GMT) X-Face: ?)Aw4rXwN5u0~$nqKj`xPz>xHCwgi^q+^?Ri*+R(&uv2=E1Q0Zk(>h!~o2ID@6{uf8s; a +M[5[U[QT7xFN%^gR"=tuJw%TXXR'Fp~W; (T"1(739R%m0Yyyv*gkGoPA.$b,D.w:z+<'"=-lVT?6 {T?=R^:W5g|E2#EhjKCa+nt":4b}dU7GYB*HBxn&Td$@f%.kl^:7X8rQWd[NTc"P"u6nkisze/Q; 8 "9Z{peQF,w)7UjV$c|RO/mQW/NMgWfr5*$-Z%u46"/00mx-,\R'fLPe.)^ User-Agent: slrn/pre1.0.0-2 (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200904/122 X-Sequence-Number: 32468 On 2009-04-24, Shawn Tayler wrote: > Hello, > > I'm doing a quick comparison between a couple tables, trying to cleanup > some inconsistencies, and what should be a simple check between 2 tables > doesn't seem to be working. psql is 8.3.7 and server is 8.2.13. > > I run the following: > > select sfd.lid as sflid,sd.lid as slid,sfd.serial from sfd,shawns_data > sd where sfd.serial = sd.serial_number order by sfd.lid; > > the lid columns in both tables should be identical, but as you see in > this sample, they do differ: > > sflid | slid | serial > -------+-------+---------- > 14056 | 14056 | 9614583 > 14057 | | 9614984 > 14058 | 14058 | 9614737 > 14059 | 14059 | 9614579 > 14060 | | 9614827 > 14061 | 14061 | 9614726 > 14062 | 14062 | 9614966 > 14063 | 14063 | 9615079 > > So running this query: > > select count(*) from sfd,shawns_data sd where sfd.serial = sd.serial_number and sfd.lid != sd.lid; > > I should show some rows that do not match, at least 2 (there are more than shown). > > But instead I get this: > > count > ------- > 0 > (1 row) > > > What am I doing wrong? expecting NULL values not-equal something. select count(*) from sfd,shawns_data sd where sfd.serial = sd.serial_number and COALESCE( sfd.lid != sd.lid, TRUE ) the above include rows where both are NULL, if that's undesirable they must be explicitly excluded.