Saturday, December 30, 2006

Postgresql VIEWs will save your day

oh yea, thats right mysql sucks ass for the complex queries, like even
select * from users where company_id in (select id from company where company_name='foo') ;
is that a join
Travis :
yea, it could be done with a join too
the above was running the output of one select into the input of a second.
:
i m doing a double join
i think it is super slow
2:04:33 pm
Travis
a join would be
select user.*
from users u, company c
where u.company_id = c.id
and c.company_name='foo'
i found with postgresql, if i was always running this sort of query
then i create a view
===================================
create or replace view v_company_users as
select user.* , c.company_name
from users u, company c
where u.company_id = c.id;
2:05:34 pm
mark
wat os a voew
2:05:40 pm
Travis
then my app does
select * from v_company_uses where company='foo'
so, instead of doing a join query and specifying parameters, create a view, and the view barfs out the values and you query the where on the view.

No comments: