dbTalk Databases Forums  

[BUGS] Question regarding 'not in' and subselects

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] Question regarding 'not in' and subselects in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vic Ricker
 
Posts: n/a

Default [BUGS] Question regarding 'not in' and subselects - 05-26-2004 , 01:02 PM






Hi. I'm using PostgreSQL 7.4.2 under Fedora Core 1.

I have two tables with a single varchar(32) column in each. I'm trying
to find all the rows from one table that don't exist in the other
table. The query that I am using is:

select u.user_name from users u where u.user_name not in (select
user_name from iasusers);

(Actually, I'm doing something a bit more complex but this illustrates
the problem.)

It always seems to return 0 rows. As a test, I inserted a row into
users that I knew wasn't in iasuses but it didn't make a difference.

If I remove the 'not', the query returns the rows that exist in both
tables.

If I replace the subselect with a list, it seems to work the way that
I'd expect, i.e. "not in ('vic', 'joe')" it shows all the rows from
users except for vic and joe.

Am I doing something wrong or is this a bug?

Thanks,
-Vic





---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
  #2  
Old   
Bruno Wolff III
 
Posts: n/a

Default Re: [BUGS] Question regarding 'not in' and subselects - 05-26-2004 , 01:39 PM






On Wed, May 26, 2004 at 13:57:37 -0400,
Vic Ricker <vicricker (AT) charter (DOT) net> wrote:
Quote:
Hi. I'm using PostgreSQL 7.4.2 under Fedora Core 1.

I have two tables with a single varchar(32) column in each. I'm trying
to find all the rows from one table that don't exist in the other
table. The query that I am using is:

select u.user_name from users u where u.user_name not in (select
user_name from iasusers);

(Actually, I'm doing something a bit more complex but this illustrates
the problem.)

It always seems to return 0 rows. As a test, I inserted a row into
users that I knew wasn't in iasuses but it didn't make a difference.

If I remove the 'not', the query returns the rows that exist in both
tables.

If I replace the subselect with a list, it seems to work the way that
I'd expect, i.e. "not in ('vic', 'joe')" it shows all the rows from
users except for vic and joe.

Am I doing something wrong or is this a bug?
Are there any nulls in iasusers.user_name?

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Vic Ricker
 
Posts: n/a

Default Re: [BUGS] Question regarding 'not in' and subselects - 05-26-2004 , 02:47 PM



On Wed, 2004-05-26 at 14:38, Bruno Wolff III wrote:
Quote:
On Wed, May 26, 2004 at 13:57:37 -0400,
Vic Ricker <vicricker (AT) charter (DOT) net> wrote:
Am I doing something wrong or is this a bug?

Are there any nulls in iasusers.user_name?
There was a null in iasusers. I removed it and that fixed the problem.
I'm not sure that I understand why. It doesn't seem very intuitive...
:-)

Tom Innes's suggestion of:

select u.user_name from users u where u.user_name not in (select
user_name from iasusers ia where ia.user_name = u.user_name);

also worked.

Thanks guys!

--
Vic Ricker
http://www.ricker.us/



---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.