Complex view question

From: "Glenn MacGregor" <gtm(at)oracom(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Complex view question
Date: 2002-01-16 19:43:36
Message-ID: 02bd01c19ec6$16e11ed0$4d00a8c0@catamount
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi All...again,

I have this complex query with a union and a not in subselect.

Query:
select xpressvim.vimname, xpressvimpermission.commandaccess, xpressvimpermission.eventaccess from xpressvim left join xpressvimpermission using (vimid) left join xpressgroup using (groupid) left join xpressuser using (groupid) where (xpressvimpermission.commandaccess is not null and xpressuser.username = 'gtm(at)jabber(dot)oracom(dot)com') union select xpressvim.vimname, xpressgroup.commandaccess, xpressgroup.eventaccess from xpressgroup left join xpressuser using (groupid) natural join xpressvim where xpressuser.username = 'gtm(at)jabber(dot)oracom(dot)com' and xpressgroup.commandaccess != 'n' and xpressvim.vimname not in (select xpressvim.vimname from xpressvim left join xpressvimpermission using (vimid) left join xpressgroup using (groupid) left join xpressuser using (groupid) where (xpressvimpermission.commandaccess is not null and xpressuser.username = 'gtm(at)jabber(dot)oracom(dot)com'));

I want to make that a view where I can change the username = '' to whatever user I need it to be. So I do the following:

create view tmpview as select xpressvim.vimname, xpressvimpermission.commandaccess, xpressvimpermission.eventaccess, xpressuser.username from xpressvim left join xpressvimpermission using (vimid) left join xpressgroup using (groupid) left join xpressuser using (groupid) union select xpressvim.vimname, xpressgroup.commandaccess, xpressgroup.eventaccess, xpressuser.username from xpressgroup left join xpressuser using (groupid) natural join xpressvim where xpressvim.vimname not in (select xpressvim.vimname from xpressvim left join xpressvimpermission using (vimid) left join xpressgroup using (groupid) left join xpressuser using (groupid));

remove all the where's except for the not in. If I now select from the view: select * from tmpview where mailto:username='gtm(at)jabber(dot)oracom(dot)com' I get results but it is not the same number of rows as the other one. The first one has the correct number of rows, the view doesn't. Did I miss something here?

Thanks

Glenn

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Doug Royer 2002-01-16 20:57:04 Re: [ANNOUNCE] Commercial: New Book!! PostgreSQL book is
Previous Message Josh Berkus 2002-01-16 16:27:39 Re: reforming query for 7.0.2