How to handle NULL values when sorting?

S.Jackson

I am looking for a way to return NULL values last when sorting either DESC or ASC in SQL (the envelopping code is in Python) and maybe be able to retun the NULL values first depending on some config

I tried replacing the NULL values with numeric values but in the long run I found that it is not a suitable solution since in some cases I need to traceback the origin of the NULL, why I have it and putting a numeric value could influence the work of someone else and give inaccurate results.

if request.sort:
    sql += " order by " + ', '.join([sort.split(':')[0] + " " + sort.split(':')[1] for sort in request.sort])

return sql
Ömrüm Çetin

Alternate way on your implementation use union all between filtered data

.... from table_name where column is not null order by column <desc/asc>
UNION ALL
.... from table_name where column is null

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

SQL how to make null values come last when sorting ascending

How to handle null values when writing to parquet from Spark

How to handle null values when a method doesn't return an Option?

How to handle null and text values when finding average in postgres?

How to handle null values when importing to CRM Online?

How to handle objects with NULL values using case_when?

How to handle "null" and "undefined" values when destructuring function arguments

How to handle null values in Angular

how to handle java null values

Ignore null values when sorting by array in MongoDB

Handle NULL values when reading through OracleDataReader?

Dealing with null values position when sorting an array based on numeric values

How to handle ExcuteScalar exceptions on Null values?

How to handle null values in SSIS script component

Guava Cache: How to handle null values

How to handle database null values in jquery datatable

ModelMapper: how to handle null values for enums

How to handle null values in gorp Select

How to handle null values /NAs in network analysis

How to handle null values in mvc view?

how to handle null values on firebase transaction api

How does Snowflake handle NULL values?

How to handle null values on first render?

How to handle SQL Server NULL values

How to handle null values in custom function?

How to handle null values when doing Collections.sort() with nested objects?

How can I handle "Null" values when returning a Python dictionary through Thrift?

How can I safely handle null values when calling Java methods from Kotlin?

String sorting null values