There appears to have been a change in postgres at some point between 9.0 and 9.1
to the aggregate method. Because of this, postgres was not returning the proper
results when pulling tags for authorities. This change will force postgres to do
a proper aggregate array call and return the correct results.
Signed-off-by: Steven Callender <stevecallender@esilibrary.com>
SELECT ARRAY_ACCUM(field) FROM authority.browse_axis_authority_field_map WHERE axis = $1;
$$ LANGUAGE SQL;
+
CREATE OR REPLACE FUNCTION authority.axis_authority_tags_refs(a TEXT) RETURNS INT[] AS $$
- SELECT ARRAY_CAT(
- ARRAY[a.field],
- (SELECT ARRAY_ACCUM(x.id) FROM authority.control_set_authority_field x WHERE x.main_entry = a.field)
- )
- FROM authority.browse_axis_authority_field_map a
- WHERE axis = $1
+ SELECT ARRAY_AGG(y) from (
+ SELECT unnest(ARRAY_CAT(
+ ARRAY[a.field],
+ (SELECT ARRAY_ACCUM(x.id) FROM authority.control_set_authority_field x WHERE x.main_entry = a.field)
+ )) y
+ FROM authority.browse_axis_authority_field_map a
+ WHERE axis = $1) x;
$$ LANGUAGE SQL;
-
CREATE OR REPLACE FUNCTION authority.btag_authority_tags(btag TEXT) RETURNS INT[] AS $$
SELECT ARRAY_ACCUM(authority_field) FROM authority.control_set_bib_field WHERE tag = $1
$$ LANGUAGE SQL;
--- /dev/null
+-- Evergreen DB patch XXXX.function.axis_authority_tags_refs_aggregate.sql
+--
+BEGIN;
+
+-- check whether patch can be applied
+SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+CREATE OR REPLACE FUNCTION authority.axis_authority_tags_refs(a TEXT) RETURNS INT[] AS $$
+ SELECT ARRAY_AGG(y) from (
+ SELECT unnest(ARRAY_CAT(
+ ARRAY[a.field],
+ (SELECT ARRAY_ACCUM(x.id) FROM authority.control_set_authority_field x WHERE x.main_entry = a.field)
+ )) y
+ FROM authority.browse_axis_authority_field_map a
+ WHERE axis = $1) x;
+$$ LANGUAGE SQL;
+
+COMMIT;