Reputation: 1855
How should I store multiple start
and end
"follow" date ranges in post_follow and query for all the post_changes to post_id within specified time ranges?
Currently, I have a tables:
post_follow:
(
user_id int,
post_id int,
start date,
end date
)
and
post_changes:
(
post_id: int,
-- ...
time timestamp
)
However, I want to add the option to unfollow/follow posts but still show the post_changes that occurred during the ranges of time that the user "follow"ed the post.
e.g. follow @ 1/1/14, unfollow @ 1/5/14, follow @ 1/10/14 ... So, in this case, I'd want to show the changes in the followed post between 1/1/14 and 1/5/14 and between 1/10/14 and the current date.
Upvotes: 0
Views: 43
Reputation: 1261
maybe a follow boolean
?
And PostgreSQL has range types timestamp range type tsrange
, and dates range daterange
.
It will make your queries easier.
Please see the PostgreSQL documentation about ranges and operators on them:
Postgresql Range types
Range operators
Upvotes: 1