Extensions: Add natural sorting for PostgreSQL (Upgrade > App Defaults to create required function).

This commit is contained in:
Nate
2019-09-09 08:21:58 -06:00
parent ad516e681c
commit 088b036b4a
2 changed files with 26 additions and 4 deletions
+14 -2
View File
@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2017
Portions created by the Initial Developer are Copyright (C) 2008-2019
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -78,6 +78,18 @@
$p->delete('default_setting_edit', 'temp');
//create natural sort function (source: http://www.rhodiumtoad.org.uk/junk/naturalsort.sql)
if ($db_type == 'pgsql') {
$sql = "create or replace function natural_sort(text)\n";
$sql .= " returns bytea language sql immutable strict as \$f\$\n";
$sql .= " select string_agg(convert_to(coalesce(r[2], length(length(r[1])::text) || length(r[1])::text || r[1]), 'SQL_ASCII'),'\\x00')\n";
$sql .= " from regexp_matches(\$1, '0*([0-9]+)|([^0-9]+)', 'g') r;\n";
$sql .= "\$f\$;";
$database = new database;
$database->execute($sql);
unset($sql);
}
}
?>
?>