2
mentions
Id
serial
MentionedUserId
int
PostId
integer
Date
timestamp with time zone
Mentions_MentionedUserId_PostId_key
MentionedUserId
PostId
Mentions_MentionedUserId_fkey
MentionedUserId
Users
restrict
restrict
Mentions_PostId_fkey
PostId
Posts
restrict
restrict
INSERT INTO
"Mentions"("MentionedUserId", "PostId", "Date")
(
SELECT
parent."PosterId" "MentionedUserId",
post."Id" "PostId",
post."LastChangeDate" "Date"
FROM "Posts" post
JOIN "Posts" parent
ON post."ParentPostId" = parent."Id"
WHERE
post."PosterId" != parent."PosterId"
ORDER BY
post."Id" asc
)