SELECT a.id AS article, count(c.*) AS comment_count FROM (articles a LEFT JOIN comments c ON (((c.article = a.id) AND (EXISTS ( SELECT comment_revisions.id, comment_revisions.comment, comment_revisions.date, comment_revisions.content, comment_revisions.author, comment_revisions.format, comment_revisions.status, comment_revisions.article_revision, comment_revisions.submitter_ip, comment_revisions.submitter_user_agent FROM comment_revisions WHERE ((comment_revisions.comment = c.id) AND ((comment_revisions.status)::text = ANY (ARRAY[('approved'::character varying)::text, ('trusted'::character varying)::text])))))))) GROUP BY a.id; SELECT article_revisions.article, article_revisions.id AS revision FROM (( SELECT article_revisions_1.id FROM article_revisions article_revisions_1 EXCEPT SELECT article_revision_parenthood.parent FROM article_revision_parenthood) branch_tips JOIN article_revisions USING (id)); SELECT article_revisions.article, min(article_revisions.date) AS publishing_date FROM article_revisions WHERE ((article_revisions.status)::text = ANY (ARRAY[('published'::character varying)::text, ('syndicated'::character varying)::text])) GROUP BY article_revisions.article; WITH RECURSIVE t(superrole, subrole) AS ( SELECT roles.id, roles.id FROM roles UNION SELECT t_1.superrole, rs.subrole FROM (t t_1 JOIN role_subroles rs ON ((rs.superrole = t_1.subrole))) ) SELECT t.superrole, t.subrole FROM t; SELECT ur."user", er.subrole AS role FROM (user_roles ur JOIN effective_role_subroles er ON ((er.superrole = ur.role))) UNION SELECT u.id AS "user", rt.role FROM users u, role_tags rt WHERE ((rt.tag)::text = ANY (ARRAY[('everyone'::character varying)::text, ('world'::character varying)::text])) UNION SELECT NULL::integer AS "user", rt.role FROM role_tags rt WHERE ((rt.tag)::text = 'world'::text); SELECT eur."user", t.message FROM effective_user_roles eur, post_targets t WHERE (t.target = eur.role) UNION SELECT m.owner AS "user", m.id AS message FROM posts m; SELECT uvp."user", uvp.message FROM (user_visible_posts uvp JOIN bookmarks bm ON ((bm.id = uvp.message))); SELECT uvp."user", uvp.message FROM (user_visible_posts uvp JOIN lazychat_messages lm ON ((lm.id = uvp.message)));