Add ability to order result set by COALESCE/MAX/MIN combination of columns. #24069
Labels
kind/feature
A request for a new feature.
team/client
Issue for team Client.
topic: orderBy / sorting
Problem
We want to sort on the result of some function of columns.
In one specific case, we need to coalesce two date columns (1 of which will always be null), and we want the newest of either column.
We may also want to sort on the greater of two columns, like Personality, Humor, or the combined value of said columns.
Suggested solution
Add to the orderBy (OrderByWithRelationInput) type:
COALESCE, MIN, MAX, AVG, ?
In postgres, this could be:
ORDER BY ...
COALESCE(col1, col2)
LEAST(col1, col2)
GREATEST(col1,col2)
(col1 + col2) / 2 -- programmatically constructed?
Alternatives
{ extraSelect: [ { name: 'recent', field: { coalesce: [ 'col1', 'col2' ] } } ], orderBy: { recent: 'desc' } }
Additional context
Listing Table:
The text was updated successfully, but these errors were encountered: