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
This commit is contained in:
Daniel Uber 2022-01-18 17:21:14 -06:00 committed by GitHub
parent 06f6573436
commit 394d33e134
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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