mirror of
https://github.com/LemmyNet/lemmy
synced 2024-10-30 15:21:20 +00:00
be1389420b
* SQL format checking, 1. * SQL format checking, 2. * SQL format checking, 3. * SQL format checking, 4. * SQL format checking, 5. * Running pg_format * Getting rid of comment. * Upping pg_format version. * Using git ls-files for sql format check. * Fixing sql lints. * Addressing PR comments.
38 lines
755 B
SQL
38 lines
755 B
SQL
-- Drop the materialized / built views
|
|
DROP VIEW reply_view;
|
|
|
|
CREATE VIEW reply_view AS
|
|
with closereply AS (
|
|
SELECT
|
|
c2.id,
|
|
c2.creator_id AS sender_id,
|
|
c.creator_id AS recipient_id
|
|
FROM
|
|
comment c
|
|
INNER JOIN comment c2 ON c.id = c2.parent_id
|
|
WHERE
|
|
c2.creator_id != c.creator_id
|
|
-- Do union where post is null
|
|
UNION
|
|
SELECT
|
|
c.id,
|
|
c.creator_id AS sender_id,
|
|
p.creator_id AS recipient_id
|
|
FROM
|
|
comment c,
|
|
post p
|
|
WHERE
|
|
c.post_id = p.id
|
|
AND c.parent_id IS NULL
|
|
AND c.creator_id != p.creator_id
|
|
)
|
|
SELECT
|
|
cv.*,
|
|
closereply.recipient_id
|
|
FROM
|
|
comment_view cv,
|
|
closereply
|
|
WHERE
|
|
closereply.id = cv.id;
|
|
|