Created
August 9, 2021 20:01
-
-
Save droserasprout/43b1f4100e14549c8a36c5a82d518237 to your computer and use it in GitHub Desktop.
PostgreSQL time series without TimescaleDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE MATERIALIZED VIEW users_30m AS | |
| SELECT | |
| a.exchange_id, | |
| COUNT(DISTINCT a.trader_id) as users, | |
| to_timestamp( | |
| floor( | |
| ( | |
| extract( | |
| 'epoch' | |
| from | |
| a.timestamp | |
| ) / 1800 | |
| ) | |
| ) * 1800 | |
| ) AT TIME ZONE 'UTC' as bucket | |
| FROM | |
| dex.activity a | |
| GROUP BY | |
| bucket, | |
| a.exchange_id; | |
| CREATE MATERIALIZED VIEW users_1w AS | |
| SELECT | |
| a.exchange_id, | |
| COUNT(DISTINCT a.trader_id) as users, | |
| date_trunc('week', a.timestamp) as bucket | |
| FROM | |
| dex.activity a | |
| GROUP BY | |
| bucket, | |
| a.exchange_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment