Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0GLRmV17945 for ; Wed, 16 Jan 2002 16:27:48 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.2) with HTTP id 621524; Wed, 16 Jan 2002 13:27:48 -0800 From: "Josh Berkus" Subject: Re: Complex view question To: "Glenn MacGregor" , "Glenn MacGregor" , X-Mailer: CommuniGate Pro Web Mailer v.3.5.2 Date: Wed, 16 Jan 2002 13:27:48 -0800 Message-ID: In-Reply-To: <031001c19ed1$754da1e0$4d00a8c0@catamount> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200201/194 X-Sequence-Number: 6280 Glenn, First, I think that you would find your own queries easier to debug if you used some indenting and line breaks to organize the text. Whenever I run into a query problem, that's what I do and frequently the missed clause or problem aggregate becomes obvious. > Query 1: returns correct number of rows > select * from overperms where username='test' union select * from > defaultperms where username='test' and vimname not in (select vimname from > overperms where username='test'); > > Query 2: return incorrect number of rows > create view perms as select * from overperms union select * from defaultperms > where vimname not in (select vimname from overperms); > > select * from perms where username='test'; These two are NOT the same query, so it's unsurprising that the counts come out different. In the second query, you are excluding ALL rows present in overperms from the count of defaultperms, not just those rows with a username of 'test'. Thus, if vimname <-> username parings are variable, you will indeed get different counts for the first query than the second. Also, I don't think that your query structure is optimal. I think you're making this harder than it needs to be. However, I can't tell without seeing your data structure. -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco