MDL-75170 dml: add sql_order_by_null method
Standardises return patterns of null values across database types to keep with sorting nullsto the top when ascending, and to the bottom when descending
This commit is contained in:
@@ -1525,6 +1525,19 @@ class pgsql_native_moodle_database extends moodle_database {
|
||||
return "STRING_AGG(" . $this->sql_cast_to_char($field) . ", '{$separator}' {$fieldsort})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the SQL text to be used to order by columns, standardising the return
|
||||
* pattern of null values across database types to sort nulls first when ascending
|
||||
* and last when descending.
|
||||
*
|
||||
* @param string $fieldname The name of the field we need to sort by.
|
||||
* @param int $sort An order to sort the results in.
|
||||
* @return string The piece of SQL code to be used in your statement.
|
||||
*/
|
||||
public function sql_order_by_null(string $fieldname, int $sort = SORT_ASC): string {
|
||||
return parent::sql_order_by_null($fieldname, $sort) . ' NULLS ' . ($sort == SORT_ASC ? 'FIRST' : 'LAST');
|
||||
}
|
||||
|
||||
public function sql_regex_supported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user