I have a function-backed column in an object table that returns a numeric value. When I sort on this column in descending order, the null values are treated as higher than the non-null values. This is a bit counterintuitive.
Seems like SQL Server treats null values as the lowest values, and Postgres may treat them as the highest values but provides for a NULLS FIRST or NULLS LAST optionality. In most use cases I can think of though, I’d want the null values at the bottom if I sort in descending order.
Is there a way to achieve this sorting (desc, nulls last) on an object table?
Thanks for posting! Currently, there is not a way to override the default sorting behavior for function-backed columns, but we will track this as an open feature request.
As a viable but non-ideal workaround, you could considering also returning a separate “Sort Order” column from your function, as this would give you complete control over how to sort nulls or any value within your primary function-backed column.