egdb3_14_1
.vandelay
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
match_set_test_authxml(match_set_id integer, record_xml text)
Parameters
Name
Type
Mode
match_set_id
integer
IN
record_xml
text
IN
Definition
DECLARE tags_rstore HSTORE; heading TEXT; coal TEXT; joins TEXT; query_ TEXT; wq TEXT; qvalue INTEGER; rec RECORD; BEGIN tags_rstore := vandelay.flatten_marc_hstore(record_xml); SELECT normalize_heading INTO heading FROM authority.normalize_heading(record_xml); CREATE TEMPORARY TABLE _vandelay_tmp_qrows (q INTEGER); CREATE TEMPORARY TABLE _vandelay_tmp_jrows (j TEXT); -- generate the where clause and return that directly (into wq), and as -- a side-effect, populate the _vandelay_tmp_[qj]rows tables. wq := vandelay.get_expr_from_match_set( match_set_id, tags_rstore, heading); query_ := 'SELECT DISTINCT(record), '; -- qrows table is for the quality bits we add to the SELECT clause SELECT STRING_AGG( 'COALESCE(n' || q::TEXT || '.quality, 0)', ' + ' ) INTO coal FROM _vandelay_tmp_qrows; -- our query string so far is the SELECT clause and the inital FROM. -- no JOINs yet nor the WHERE clause query_ := query_ || coal || ' AS quality ' || E'\n'; -- jrows table is for the joins we must make (and the real text conditions) SELECT STRING_AGG(j, E'\n') INTO joins FROM _vandelay_tmp_jrows; -- add those joins and the where clause to our query. query_ := query_ || joins || E'\n'; query_ := query_ || 'JOIN authority.record_entry are ON (are.id = record) ' || 'WHERE ' || wq || ' AND not are.deleted'; -- this will return rows of record,quality FOR rec IN EXECUTE query_ USING tags_rstore LOOP RETURN NEXT rec; END LOOP; DROP TABLE _vandelay_tmp_qrows; DROP TABLE _vandelay_tmp_jrows; RETURN; END;