Advertisement
Guest User

Untitled

a guest
Oct 26th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. @@ -85,23 +85,20 @@ BEGIN
  2. CONTINUE WHEN ind_data.sort_value IS NULL;
  3.  
  4. value_prepped := metabib.browse_normalize(ind_data.value, ind_data.field);
  5. - IF ind_data.browse_nocase THEN
  6. + IF ind_data.browse_nocase THEN -- for "nocase" browse definions, look for a preexisting row that matches case-insensitively on value and use that
  7. SELECT INTO mbe_row * FROM metabib.browse_entry
  8. WHERE evergreen.lowercase(value) = evergreen.lowercase(value_prepped) AND sort_value = ind_data.sort_value
  9. ORDER BY sort_value, value LIMIT 1; -- gotta pick something, I guess
  10. - ELSE
  11. - SELECT INTO mbe_row * FROM metabib.browse_entry
  12. - WHERE value = value_prepped AND sort_value = ind_data.sort_value;
  13. END IF;
  14.  
  15. - IF FOUND THEN
  16. + IF mbe_row.id IS NOT NULL THEN -- asked to check for, and found, a "nocase" version to use
  17. mbe_id := mbe_row.id;
  18. - ELSE
  19. + ELSE -- otherwise, an UPSERT-protected variant
  20. INSERT INTO metabib.browse_entry
  21. ( value, sort_value ) VALUES
  22. - ( value_prepped, ind_data.sort_value );
  23. -
  24. - mbe_id := CURRVAL('metabib.browse_entry_id_seq'::REGCLASS);
  25. + ( value_prepped, ind_data.sort_value )
  26. + ON CONFLICT (sort_value, value) DO UPDATE SET id = EXCLUDED.id -- must update a row to return an existing id
  27. + RETURNING id INTO mbe_id;
  28. END IF;
  29.  
  30. INSERT INTO metabib.browse_entry_def_map (entry, def, source, authority)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement