What is the best way to handle materialized views with different timezones?
0
votes
1
answer
83
views
I am building some API endpoints backed by materialized views (I am using Ruby on Rails).
The data is from Quake Live and it basically contains game stats (weapon accuracy, damage dealt, etc).
I want to have a materialized view for damage done today (midnight to current time), this week, this month, this year and all time.
This is the current SQL used to create the materialized view:
SELECT
players.id AS player_id,
players.name AS player_name,
players.steam_id AS steam_id,
SUM(stats.damage_dealt) AS total_damage_dealt,
SUM(stats.damage_taken) AS total_damage_taken
FROM
stats
JOIN
players ON players.id = stats.player_id
WHERE
stats.created_at >= date_trunc('day', NOW())
GROUP BY
players.id, players.steam_id;
It works, however I want to add support for multiple timezones, so that if you request stats for today with X timezone, the materialized views will reflect that.
So far the only thing I could think of is creating a different materialized view for each timezone (not doable).
My question is if anyone has a hint on what I could do other than dynamically query my tables with created_at, which would make the use of materialized views useless if not for all time stats. Cheers.
Asked by devamat
(111 rep)
Jan 21, 2025, 01:45 PM
Last activity: Jan 22, 2025, 08:22 AM
Last activity: Jan 22, 2025, 08:22 AM