From f4a8be6c1944dd581e568bac6c8698bb3cdb4805 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 25 Nov 2020 12:01:00 -0300 Subject: [PATCH] use coalesce to high value instead of nulls last to be ANSI compatible --- lbry/db/queries/search.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lbry/db/queries/search.py b/lbry/db/queries/search.py index 97265050c..0c8205b92 100644 --- a/lbry/db/queries/search.py +++ b/lbry/db/queries/search.py @@ -148,12 +148,12 @@ def select_claims(cols: List = None, for_count=False, **constraints) -> Select: raise NameError(f'{column} is not a valid order_by field') if column == 'name': column = 'claim_name' - nulls_last = '' - if column in ('trending_group', 'trending_mixed', 'release_time'): - nulls_last = ' NULLs LAST' table = "trend" if column.startswith('trend') else "claim" + column = f"{table}.{column}" + if column in ('trending_group', 'trending_mixed', 'release_time'): + column = f"COALESCE({column}, {1<<32})" sql_order_by.append( - f"{table}.{column} ASC{nulls_last}" if is_asc else f"{table}.{column} DESC{nulls_last}" + f"{column} {'ASC' if is_asc else 'DESC'}" ) constraints['order_by'] = sql_order_by