Re: Complex view question - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Complex view question
Date
Msg-id web-621524@davinci.ethosmedia.com
Whole thread Raw
In response to Re: Complex view question  ("Glenn MacGregor" <gtm@oracom.com>)
List pgsql-sql
Glenn,

First, I think that you would find your own queries easier to debug if you usedsome indenting and line breaks to
organizethe text.  Whenever I run into aquery problem, that's what I do and frequently the missed clause or
problemaggregatebecomes 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 outdifferent.  In the second query, you are
excludingALL rows present inoverperms from the count of defaultperms, not just those rows with a usernameof 'test'.
Thus,if vimname <-> username parings are variable, you willindeed get different counts for the first query than the
second.

Also, I don't think that your query structure is optimal.  I think you'remaking this harder than it needs to be.
However,I can't tell without seeingyour data structure.
 

-Josh Berkus

______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


pgsql-sql by date:

Previous
From: "Glenn MacGregor"
Date:
Subject: Re: Complex view question
Next
From: "Glenn MacGregor"
Date:
Subject: Re: Complex view question