-
Improvement
-
Resolution: Fixed
-
Minor
-
4.0.1, 4.1
-
MOODLE_400_STABLE, MOODLE_401_STABLE
-
MOODLE_401_STABLE
-
MDL-75170-master-add_order_by_method -
Note: the final decision was made to implement this in base table libraries, rather than in report builder only - see comments
Postgres treats null values as if larger than any non-null value - this is not natural for most reports based on counts/integers etc.
For example if you are showing a report with the number of views a user has, but one user doesn't have any - and the result returns "null" - ordering by the views DESC will order the null value at the top.
user | views
dan null
john 5
simon 3
bob 1
It's not easy to change this..
we could dig into the tablelib.php class and change the default like this:
--- a/lib/tablelib.php
|
+++ b/lib/tablelib.php
|
@@ -601,9 +601,9 @@ class flexible_table { |
$column = $DB->sql_order_by_text($column);
|
}
|
if ($order == SORT_ASC) { |
- $bits[] = $column . ' ASC'; |
+ $bits[] = $column . ' ASC NULLS FIRST'; |
} else { |
- $bits[] = $column . ' DESC'; |
+ $bits[] = $column . ' DESC NULLS LAST'; |
}
|
}
|
but that affects a lot of different reports, is not cross-db compatible, and in some cases sorting null using the default option may in fact be useful...
I think the reportbuilder class should implement it's own sort handling (rather than relying on tablelib.php) and allow a report datasource or entity to define how the null values are sorted - then have some form of cross-db support to handle it.