summaryrefslogtreecommitdiffstats
path: root/Bugzilla/DB/Pg.pm
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-07 02:13:46 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-07-07 02:13:46 +0200
commit333b8fcbaad05e5e3ab01a897529560dea37dd53 (patch)
tree7082f8e981412dcf053c8d9554f56785ea7327d8 /Bugzilla/DB/Pg.pm
parent569c6b69a7cb3c458279efbdfed1b104cd3d9ae5 (diff)
downloadbugzilla-333b8fcbaad05e5e3ab01a897529560dea37dd53.tar.gz
bugzilla-333b8fcbaad05e5e3ab01a897529560dea37dd53.tar.xz
Bug 552919: Sort group_concat results so that they sort correctly for buglists
r=mkanat, a=mkanat (module owner)
Diffstat (limited to 'Bugzilla/DB/Pg.pm')
-rw-r--r--Bugzilla/DB/Pg.pm25
1 files changed, 22 insertions, 3 deletions
diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm
index c85c1d710..018900129 100644
--- a/Bugzilla/DB/Pg.pm
+++ b/Bugzilla/DB/Pg.pm
@@ -98,9 +98,14 @@ sub bz_last_key {
}
sub sql_group_concat {
- my ($self, $text, $separator) = @_;
- $separator ||= "','";
- return "array_to_string(array_accum($text), $separator)";
+ my ($self, $text, $separator, $sort) = @_;
+ $sort = 1 if !defined $sort;
+ $separator = $self->quote(', ') if !defined $separator;
+ my $sql = "array_accum($text)";
+ if ($sort) {
+ $sql = "array_sort($sql)";
+ }
+ return "array_to_string($sql, $separator)";
}
sub sql_istring {
@@ -224,6 +229,20 @@ sub bz_setup_database {
)");
}
+ $self->do(<<'END');
+CREATE OR REPLACE FUNCTION array_sort(ANYARRAY)
+RETURNS ANYARRAY LANGUAGE SQL
+IMMUTABLE STRICT
+AS $$
+SELECT ARRAY(
+ SELECT $1[s.i] AS each_item
+ FROM
+ generate_series(array_lower($1,1), array_upper($1,1)) AS s(i)
+ ORDER BY each_item
+);
+$$;
+END
+
# PostgreSQL doesn't like having *any* index on the thetext
# field, because it can't have index data longer than 2770
# characters on that field.