-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
pragma-entities/migrations/2024-02-20-090454_fix_twap_aggs/down.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER MATERIALIZED VIEW twap_2_hours_agg SET SCHEMA ( | ||
SELECT | ||
pair_id, | ||
time_bucket('2 hours'::interval, timestamp) as bucket, | ||
average(time_weight('Linear', timestamp, price))::numeric as price_twap, | ||
COUNT(DISTINCT source) as num_sources | ||
FROM entries | ||
GROUP BY bucket, pair_id | ||
) |
16 changes: 16 additions & 0 deletions
16
pragma-entities/migrations/2024-02-20-090454_fix_twap_aggs/up.sql
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Your SQL goes here | ||
ALTER MATERIALIZED VIEW twap_2_hours_agg SET SCHEMA ( | ||
SELECT | ||
pair_id, | ||
time_bucket('2 hours'::interval, timestamp) as bucket, | ||
interpolated_average( | ||
time_weight('Linear', timestamp, price), | ||
bucket, | ||
'2 hours'::interval, | ||
lag(agg) OVER (ORDER BY bucket), | ||
lead(agg) OVER (ORDER BY bucket) | ||
)::numeric as price_twap, | ||
COUNT(DISTINCT source) as num_sources | ||
FROM entries | ||
GROUP BY bucket, pair_id | ||
) |