diff options
author | mkanat%bugzilla.org <> | 2009-08-17 23:31:02 +0200 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2009-08-17 23:31:02 +0200 |
commit | ef1a85038621e7e13ff850e9b1c33b504ebcde35 (patch) | |
tree | 6ce13d8993729c4af32732ec5caa562a5d41cda9 /Bugzilla/DB/Pg.pm | |
parent | c023c92ea3bd7cf256d51557be29cfea1c055b01 (diff) | |
download | bugzilla-ef1a85038621e7e13ff850e9b1c33b504ebcde35.tar.gz bugzilla-ef1a85038621e7e13ff850e9b1c33b504ebcde35.tar.xz |
Bug 509497: Implement sql_group_concat for all databases
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=mkanat
Patch by Xiaoou Wu <xiaoou.wu@oracle.com> r=mkanat, a=mkanat
Diffstat (limited to 'Bugzilla/DB/Pg.pm')
-rw-r--r-- | Bugzilla/DB/Pg.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index 18f9abf88..585c0884b 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -94,6 +94,12 @@ sub bz_last_key { return $last_insert_id; } +sub sql_group_concat { + my ($self, $text, $separator) = @_; + $separator ||= "','"; + return "array_to_string(array_accum($text), $separator)"; +} + sub sql_regexp { my ($self, $expr, $pattern, $nocheck, $real_pattern) = @_; $real_pattern ||= $pattern; @@ -189,6 +195,20 @@ sub bz_setup_database { my $self = shift; $self->SUPER::bz_setup_database(@_); + # Custom Functions + my $function = 'array_accum'; + my $array_accum = $self->selectrow_array( + 'SELECT 1 FROM pg_proc WHERE proname = ?', undef, $function); + if (!$array_accum) { + print "Creating function $function...\n"; + $self->do("CREATE AGGREGATE array_accum ( + SFUNC = array_append, + BASETYPE = anyelement, + STYPE = anyarray, + INITCOND = '{}' + )"); + } + # 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. |