From 394d33e1348bca5f0ddc7f357895b86d7b6763bc Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Tue, 18 Jan 2022 17:21:14 -0600 Subject: [PATCH] Select max from a subquery of two things (#16177) * Select max from a subquery of two things max(int, int) not a function, says postgres, once it stopped yelling about parenthesis balancing. * prefer greatest to select max from subquery --- app/services/articles/feeds/weighted_query_strategy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/articles/feeds/weighted_query_strategy.rb b/app/services/articles/feeds/weighted_query_strategy.rb index dcbcbe05c..735e94a22 100644 --- a/app/services/articles/feeds/weighted_query_strategy.rb +++ b/app/services/articles/feeds/weighted_query_strategy.rb @@ -462,7 +462,7 @@ module Articles when "final_order_by_random_weighted_to_last_comment_at" # rubocop:disable Layout/LineLength articles - .order(Arel.sql("RANDOM() ^ (1.0 / (max(1, (extract(epoch from now() - articles.last_comment_at)::integer)) ASC")) + .order(Arel.sql("RANDOM() ^ (1.0 / greatest( 1, (extract(epoch from now() - articles.last_comment_at)::integer))) ASC")) # rubocop:enable Layout/LineLength else # original articles