Lp 1947595: Remove the array_accum aggregate function
authorJason Stephenson <jason@sigio.com>
Wed, 20 Oct 2021 16:38:46 +0000 (12:38 -0400)
committerJane Sandberg <sandbergja@gmail.com>
Fri, 11 Feb 2022 03:23:20 +0000 (19:23 -0800)
Remove the array_accum aggregate from Evergreen because it will need
to be dropped and redefined when upgrading to PostgreSQL 14.

Replace any uses of array_accum with array_agg in the code.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Jason Boyer <JBoyer@equinoxOLI.org>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Booking.pm
Open-ILS/src/sql/Pg/002.functions.aggregate.sql
Open-ILS/src/sql/Pg/t/search_limit_facet_fetch.pg
Open-ILS/src/sql/Pg/upgrade/XXXX.function.remove-array_accum.sql [new file with mode: 0644]
docs/RELEASE_NOTES_NEXT/API/array-accum-removed.adoc [new file with mode: 0644]

index 8b48d7c..ca556fb 100644 (file)
@@ -351,7 +351,7 @@ sub resource_list_by_attrs {
             if (!ref($filters->{attribute_values}));
 
         $query->{having}->{'+bram'}->{value}->{'@>'} = {
-            transform => 'array_accum',
+            transform => 'array_agg',
             value => '$_' . $$ . '${' .
                 join(',', @{$filters->{attribute_values}}) .
                 '}$_' . $$ . '$'
@@ -554,7 +554,7 @@ sub reservation_list_by_filters {
             if (!ref($filters->{attribute_values}));
 
         $query->{having}->{'+bravm'}->{attr_value}->{'@>'} = {
-            transform => 'array_accum',
+            transform => 'array_agg',
             value => '$_' . $$ . '${' .
                 join(',', @{$filters->{attribute_values}}) .
                 '}$_' . $$ . '$'
index cb42cd7..49eda40 100644 (file)
 
 BEGIN;
 
-DROP AGGREGATE IF EXISTS array_accum(anyelement) CASCADE;
 DROP AGGREGATE IF EXISTS public.first(anyelement) CASCADE;
 DROP AGGREGATE IF EXISTS public.last(anyelement) CASCADE;
 DROP AGGREGATE IF EXISTS public.agg_text(text) CASCADE;
 
-CREATE AGGREGATE array_accum (
-       sfunc = array_append,
-       basetype = anyelement,
-       stype = anyarray,
-       initcond = '{}'
-);
-
 CREATE OR REPLACE FUNCTION public.first_agg ( anyelement, anyelement ) RETURNS anyelement AS $$
        SELECT CASE WHEN $1 IS NULL THEN $2 ELSE $1 END;
 $$ LANGUAGE SQL STABLE;
index 86023ce..a302d1e 100644 (file)
@@ -64,7 +64,7 @@ SELECT is(
 SELECT is(
     (
         SELECT COUNT(*) FROM (
-            SELECT search.facets_for_metarecord_set('{}', array_accum(metarecord))
+            SELECT search.facets_for_metarecord_set('{}', array_agg(metarecord))
             FROM metabib.metarecord_source_map
             WHERE source = 999999998
         ) x
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.remove-array_accum.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.remove-array_accum.sql
new file mode 100644 (file)
index 0000000..864f23f
--- /dev/null
@@ -0,0 +1,7 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+DROP AGGREGATE IF EXISTS array_accum(anyelement) CASCADE;
+
+COMMIT;
diff --git a/docs/RELEASE_NOTES_NEXT/API/array-accum-removed.adoc b/docs/RELEASE_NOTES_NEXT/API/array-accum-removed.adoc
new file mode 100644 (file)
index 0000000..dd5a996
--- /dev/null
@@ -0,0 +1,10 @@
+== array_accum Aggregate Removed ==
+
+The custom `array_accum` aggregate function has been removed from the
+PostgreSQL database because it will need to be dropped and recreated
+with a different definition when upgrading to PostgreSQL version 14 or
+later.  Its functionality is also redundant with PostgreSQL's own
+`array_agg` function.
+
+Sites that have custom code using Evergreen's `array_accum` function
+should alter their code to use `array_agg` instead.