postgresql7.1 select p.portal_id, p.name, t.filename as template, t.template_id, case when p.owner_id = null then 1 else 0 end as default_portal_p, case when acs_permission__permission_p(p.template_id, :user_id, 'read') = 't' then 1 else 0 end as template_read_p from portals p, portal_templates t where p.template_id = t.template_id and p.portal_id = :portal_id