Something
public text v1 · immutableSELECT DISTINCT ON (post.id) count(post.id) AS count
FROM list_posts AS post
LEFT OUTER JOIN private ON (post.id = private.pid)
LEFT OUTER JOIN official_user AS adminu ON (adminu.user = adminu.user)
LEFT OUTER JOIN count_comments AS ccount ON (post.id = ccount.pid)
WHERE
adminu.user = %s --User is the official_user
OR
(post.private = false --Post is not private
OR private.uid = %s --User is allowed to view post
)