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

* varchar value comparisons not working?
@ 2009-04-24 13:59  Shawn Tayler <stayler@washoecounty.us>
  0 siblings, 2 replies; 3+ messages in thread

From: Shawn Tayler @ 2009-04-24 13:59 UTC (permalink / raw)
  To: pgsql-sql

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?


-- 
Sincerely,

Shawn Tayler
Radio Network Administrator
Washoe County Regional Communications System
Telecommunications Division
Technology Services Department
County of Washoe
State of Nevada
Ofc  (775)858-5952
Cell (775)771-4241
FAX  (775)858-5960




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

* Re: varchar value comparisons not working?
@ 2009-04-24 14:32  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Shawn Tayler <stayler@washoecounty.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2009-04-24 14:32 UTC (permalink / raw)
  To: stayler@washoecounty.us; +Cc: pgsql-sql

Shawn Tayler <stayler@washoecounty.us> writes:
> 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)

Probably those "blank" values of slid are really NULLs.  A NULL isn't
"equal to" something else, but it isn't "unequal" either.  You could
use IS DISTINCT FROM instead of != in your second query.

			regards, tom lane



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

* Re: varchar value comparisons not working?
@ 2009-04-27 08:53  Jasen Betts <jasen@xnet.co.nz>
  parent: Shawn Tayler <stayler@washoecounty.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Jasen Betts @ 2009-04-27 08:53 UTC (permalink / raw)
  To: pgsql-sql

On 2009-04-24, Shawn Tayler <stayler@washoecounty.us> 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.



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


end of thread, other threads:[~2009-04-27 08:53 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-04-24 13:59 varchar value comparisons not working? Shawn Tayler <stayler@washoecounty.us>
2009-04-24 14:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2009-04-27 08:53 ` Jasen Betts <jasen@xnet.co.nz>

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