diff options
Diffstat (limited to 'db/rest/post/api_post.sql')
-rw-r--r-- | db/rest/post/api_post.sql | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/db/rest/post/api_post.sql b/db/rest/post/api_post.sql index b49289c..375f292 100644 --- a/db/rest/post/api_post.sql +++ b/db/rest/post/api_post.sql @@ -3,10 +3,21 @@ CREATE VIEW api.post AS p.id, p.user_id, p.content, - p.date + p.date, + COALESCE(c.cc, 0) + AS comment_count FROM admin.post p - ORDER BY id DESC; + LEFT JOIN ( + SELECT + COUNT(c.id) as cc, + c.post_id + FROM + admin.comment c + GROUP BY + c.post_id + ) c ON p.id = c.post_id + ORDER BY p.id DESC; GRANT SELECT ON TABLE api.post TO rest_anon, rest_user; |