-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
15 additions
and
0 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
supabase/migrations/20240708094214_fix_db_stats_function.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,14 @@ | ||
drop function if exists get_monthly_weather(); | ||
|
||
CREATE OR REPLACE FUNCTION public.get_monthly_weather() | ||
RETURNS TABLE(month text, avg_temperature_celsius double precision, max_temperature_celsius double precision, total_rainfall_liters double precision) | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT to_char(daily_weather_data.measure_day, 'yyyy-mm') AS month, AVG(daily_weather_data.avg_temperature_celsius) as avg_temperature_celsius, MAX(daily_weather_data.avg_temperature_celsius) as max_temperature_celsius, SUM(daily_weather_data.sum_precipitation_mm_per_sqm) as total_rainfall_liters | ||
FROM daily_weather_data | ||
GROUP BY to_char(daily_weather_data.measure_day, 'yyyy-mm') | ||
ORDER BY to_char(daily_weather_data.measure_day, 'yyyy-mm') DESC; | ||
END; | ||
$function$ |