BEGIN;
+CREATE OR REPLACE FUNCTION metabib.browse_pivot(
+ search_field INT[], browse_term TEXT
+) RETURNS BIGINT AS $p$
+-- handles 'search_field' conflict. using this means I don't
+-- have to drop/recreate the function and those that rely on it
+-- just to change the 'search_field' param name.
+#variable_conflict use_variable
+DECLARE
+ sort_value TEXT;
+BEGIN
+ SELECT INTO sort_value
+ CASE WHEN cmf.field_class = 'identifier' THEN
+ public.naco_normalize_keep_decimal($2, '')
+ ELSE
+ public.naco_normalize($2)
+ END
+ FROM config.metabib_field cmf
+ WHERE cmf.id = search_field[1];
+
+ RETURN id FROM metabib.browse_entry
+ WHERE metabib_fields_cache && $1
+ AND combo_sort_value >= sort_value
+ ORDER BY combo_sort_value LIMIT 1;
+END;
+$p$ LANGUAGE PLPGSQL STABLE;
+
+
DO $INSERT$
BEGIN
IF evergreen.insert_on_deploy() THEN