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; 8:d3297cb8b06a3c8e0c2df40bb21ba4d3 9:1ddb31e4daad9a3e759f908348d585df 8:4916246f4404e8621541c84fbc770427 9:8e65575f838c89b5963c00deb9d41ca9 8:8193d6d6df241e604e3cd54cd7584229 9:b388ba620250e303e711546b7e8c79a7 CREATE SCHEMA IF NOT EXISTS benki WITH RECURSIVE t(superrole, subrole) AS ( SELECT roles.id, roles.id FROM benki.roles roles UNION SELECT t_1.superrole, rs.subrole FROM (t t_1 JOIN benki.role_subroles rs ON ((rs.superrole = t_1.subrole))) ) SELECT t.superrole, t.subrole FROM t; SELECT ur."user", er.subrole AS role FROM (benki.user_roles ur JOIN benki.effective_role_subroles er ON ((er.superrole = ur.role))) UNION SELECT u.id AS "user", rt.role FROM benki.users u, benki.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 benki.role_tags rt WHERE ((rt.tag)::text = 'world'::text); SELECT eur."user", t.message FROM benki.effective_user_roles eur, benki.post_targets t WHERE (t.target = eur.role) UNION SELECT m.owner AS "user", m.id AS message FROM benki.posts m; SELECT uvp."user", uvp.message FROM (benki.user_visible_posts uvp JOIN benki.bookmarks bm ON ((bm.id = uvp.message))); SELECT uvp."user", uvp.message FROM (benki.user_visible_posts uvp JOIN benki.lazychat_messages lm ON ((lm.id = uvp.message)));