vandelay.queued_authority_record
|
Data-Modifying Triggers: This table has BEFORE ROW trigger(s) that modify row data before write. Values you INSERT or UPDATE may differ from what is actually stored. See the Triggers section below. |
|
Cascading Deletes: Deleting rows from this table will cascade to: vandelay.authority_queue. |
|
Deferrable Constraints: The following FK constraints are deferrable — they are checked at transaction end, not statement end: |
|
Trigger Side Effects: Writing to this table automatically triggers writes to other tables:
|
Columns
| Column | Type | Nullable | Default | Notes |
|---|---|---|---|---|
id PK |
|
No |
nextval('vandelay.queued_record_id_seq'::regclass) |
|
create_time |
|
No |
now() |
|
import_time |
|
Yes |
||
purpose |
|
No |
'import'::text |
|
marc |
|
No |
||
quality |
|
No |
0 |
|
queue FK |
|
No |
||
imported_as FK |
|
Yes |
||
import_error FK |
|
Yes |
||
error_detail |
|
Yes |
Foreign Keys
| Column(s) | References | On Delete | On Update | Deferrable | Constraint |
|---|---|---|---|---|---|
|
SET NULL |
CASCADE |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
CASCADE |
NO ACTION |
DEFERRED |
|
Check Constraints
-
queued_record_purpose_check:CHECK purpose = ANY (ARRAY['import'::text, 'overlay'::text])
Indexes
| Index | Method | Definition |
|---|---|---|
|
btree |
|
|
btree |
|
Triggers
| Trigger | Timing | Event | Level | Function |
|---|---|---|---|---|
|
BEFORE |
DELETE OR UPDATE |
ROW |
|
|
AFTER |
INSERT OR UPDATE |
ROW |
|
|
BEFORE |
INSERT OR UPDATE |
ROW |
Trigger Bodies
cleanup_authority_trigger
Function: vandelay.cleanup_authority_marc()
Timing: BEFORE DELETE OR UPDATE ROW
|
This trigger modifies the row before it is written (returns a modified |
BEGIN
IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN
RETURN NEW;
END IF;
DELETE FROM vandelay.queued_authority_record_attr WHERE record = OLD.id;
IF TG_OP = 'UPDATE' THEN
RETURN NEW;
END IF;
RETURN OLD;
END;
ingest_authority_trigger
Function: vandelay.ingest_authority_marc()
Timing: AFTER INSERT OR UPDATE ROW
DECLARE
value TEXT;
atype TEXT;
adef RECORD;
BEGIN
IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN
RETURN NEW;
END IF;
FOR adef IN SELECT * FROM vandelay.authority_attr_definition LOOP
SELECT extract_marc_field('vandelay.queued_authority_record', id, adef.xpath, adef.remove) INTO value FROM vandelay.queued_authority_record WHERE id = NEW.id;
IF (value IS NOT NULL AND value <> '') THEN
INSERT INTO vandelay.queued_authority_record_attr (record, field, attr_value) VALUES (NEW.id, adef.id, value);
END IF;
END LOOP;
RETURN NULL;
END;
zz_match_auths_trigger
Function: vandelay.match_authority_record()
Timing: BEFORE INSERT OR UPDATE ROW
|
This trigger modifies the row before it is written (returns a modified |
DECLARE
incoming_existing_id TEXT;
test_result vandelay.match_set_test_result%ROWTYPE;
tmp_rec BIGINT;
match_set INT;
BEGIN
IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN
RETURN NEW;
END IF;
DELETE FROM vandelay.authority_match WHERE queued_record = NEW.id;
SELECT q.match_set INTO match_set FROM vandelay.authority_queue q WHERE q.id = NEW.queue;
IF match_set IS NOT NULL THEN
NEW.quality := vandelay.measure_auth_record_quality( NEW.marc, match_set );
END IF;
-- Perfect matches on 901$c exit early with a match with high quality.
incoming_existing_id :=
oils_xpath_string('//*[@tag="901"]/*[@code="c"][1]', NEW.marc);
IF incoming_existing_id IS NOT NULL AND incoming_existing_id != '' THEN
SELECT id INTO tmp_rec FROM authority.record_entry WHERE id = incoming_existing_id::bigint;
IF tmp_rec IS NOT NULL THEN
INSERT INTO vandelay.authority_match (queued_record, eg_record, match_score, quality)
SELECT
NEW.id,
b.id,
9999,
-- note: no match_set means quality==0
vandelay.measure_auth_record_quality( b.marc, match_set )
FROM authority.record_entry b
WHERE id = incoming_existing_id::bigint;
END IF;
END IF;
IF match_set IS NULL THEN
RETURN NEW;
END IF;
FOR test_result IN SELECT * FROM
vandelay.match_set_test_authxml(match_set, NEW.marc) LOOP
INSERT INTO vandelay.authority_match ( queued_record, eg_record, match_score, quality )
SELECT
NEW.id,
test_result.record,
test_result.quality,
vandelay.measure_auth_record_quality( b.marc, match_set )
FROM authority.record_entry b
WHERE id = test_result.record;
END LOOP;
RETURN NEW;
END;