Re: [GENERAL] Querying all documents for a company and its projects etc

2014-04-16 Thread Fede Martinez
what about resolving the join "document doc JOIN document_usage du ON doc.id = du.document_id" using WITH? I think this won't work because the result of this CTE would be huge, but you could get the company with that id first using a WITH clause too, then you would have the name and you wouldn't ha

Re: [GENERAL] Querying all documents for a company and its projects etc

2014-04-16 Thread Andreas Joseph Krogh
På mandag 14. april 2014 kl. 21:55:26, skrev David G Johnston < david.g.johns...@gmail.com >: A couple of thoughts: 1) The "union" really only pertains to the entity table rows; once you "union all" those (duplicates should not matter and probably will not eve

Re: [GENERAL] Querying all documents for a company and its projects etc

2014-04-15 Thread David G Johnston
A couple of thoughts: 1) The "union" really only pertains to the entity table rows; once you "union all" those (duplicates should not matter and probably will not even be present so using "all" avoids an unnecessary sort) you can join that sub-query to the document_usage table. 2) Since every ent

[GENERAL] Querying all documents for a company and its projects etc

2014-04-14 Thread Andreas Joseph Krogh
Hi all.   I'm trying to make an efficient query to list all documents related to a company and also documents related to employees and projects for that company.   I have this sample-schema: create table entity( id integer primary key, entity_type varchar not null, check (entity_type IN ('COMPAN