From 8dfb1f99ae8e3f509e4dbd663ab9304af429e28e Mon Sep 17 00:00:00 2001 From: Yaroslav Podorvanov Date: Sun, 23 Jun 2024 01:01:51 +0300 Subject: [PATCH] fix zeros --- internal/storage/dbs/profile_hourly_views_stats.sql.go | 6 +++--- internal/storage/queries/profile_hourly_views_stats.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/storage/dbs/profile_hourly_views_stats.sql.go b/internal/storage/dbs/profile_hourly_views_stats.sql.go index 453a40c..c8e964e 100644 --- a/internal/storage/dbs/profile_hourly_views_stats.sql.go +++ b/internal/storage/dbs/profile_hourly_views_stats.sql.go @@ -14,9 +14,9 @@ import ( const profileHourlyViewsStats = `-- name: ProfileHourlyViewsStats :many SELECT user_id, - SUM(count) FILTER ( WHERE time >= $1 ) AS day_count, - SUM(count) FILTER ( WHERE time >= $2 ) AS week_count, - SUM(count) AS month_count + COALESCE(SUM(count) FILTER ( WHERE time >= $1 ), 0)::BIGINT AS day_count, + COALESCE(SUM(count) FILTER ( WHERE time >= $2 ), 0)::BIGINT AS week_count, + SUM(count) AS month_count FROM profile_hourly_views_stats WHERE user_id = ANY ($3::BIGINT[]) AND time >= $4 diff --git a/internal/storage/queries/profile_hourly_views_stats.sql b/internal/storage/queries/profile_hourly_views_stats.sql index 7781821..cb1c408 100644 --- a/internal/storage/queries/profile_hourly_views_stats.sql +++ b/internal/storage/queries/profile_hourly_views_stats.sql @@ -6,9 +6,9 @@ ON CONFLICT (user_id, time) DO UPDATE -- name: ProfileHourlyViewsStats :many SELECT user_id, - SUM(count) FILTER ( WHERE time >= @day ) AS day_count, - SUM(count) FILTER ( WHERE time >= @week ) AS week_count, - SUM(count) AS month_count + COALESCE(SUM(count) FILTER ( WHERE time >= @day ), 0)::BIGINT AS day_count, + COALESCE(SUM(count) FILTER ( WHERE time >= @week ), 0)::BIGINT AS week_count, + SUM(count) AS month_count FROM profile_hourly_views_stats WHERE user_id = ANY (@user_ids::BIGINT[]) AND time >= @month