vandelay.queued_bib_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.bib_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 |
||
bib_source FK |
|
Yes |
||
imported_as FK |
|
Yes |
||
import_error FK |
|
Yes |
||
error_detail |
|
Yes |
Foreign Keys
| Column(s) | References | On Delete | On Update | Deferrable | Constraint |
|---|---|---|---|---|---|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
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 |
|
|
AFTER |
INSERT OR UPDATE |
ROW |
|
|
BEFORE |
INSERT OR UPDATE |
ROW |
Trigger Bodies
cleanup_bib_trigger
Function: vandelay.cleanup_bib_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_bib_record_attr WHERE record = OLD.id;
DELETE FROM vandelay.import_item WHERE record = OLD.id;
IF TG_OP = 'UPDATE' THEN
RETURN NEW;
END IF;
RETURN OLD;
END;
ingest_bib_trigger
Function: vandelay.ingest_bib_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.bib_attr_definition LOOP
SELECT extract_marc_field('vandelay.queued_bib_record', id, adef.xpath, adef.remove) INTO value FROM vandelay.queued_bib_record WHERE id = NEW.id;
IF (value IS NOT NULL AND value <> '') THEN
INSERT INTO vandelay.queued_bib_record_attr (record, field, attr_value) VALUES (NEW.id, adef.id, value);
END IF;
END LOOP;
RETURN NULL;
END;
ingest_item_trigger
Function: vandelay.ingest_bib_items()
Timing: AFTER INSERT OR UPDATE ROW
DECLARE
attr_def BIGINT;
item_data vandelay.import_item%ROWTYPE;
BEGIN
IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN
RETURN NEW;
END IF;
SELECT item_attr_def INTO attr_def FROM vandelay.bib_queue WHERE id = NEW.queue;
FOR item_data IN SELECT * FROM vandelay.ingest_items( NEW.id::BIGINT, attr_def ) LOOP
INSERT INTO vandelay.import_item (
record,
definition,
owning_lib,
circ_lib,
call_number,
copy_number,
status,
location,
circulate,
deposit,
deposit_amount,
ref,
holdable,
price,
barcode,
circ_modifier,
circ_as_type,
alert_message,
pub_note,
priv_note,
internal_id,
opac_visible,
stat_cat_data,
parts_data,
import_error,
error_detail
) VALUES (
NEW.id,
item_data.definition,
item_data.owning_lib,
item_data.circ_lib,
item_data.call_number,
item_data.copy_number,
item_data.status,
item_data.location,
item_data.circulate,
item_data.deposit,
item_data.deposit_amount,
item_data.ref,
item_data.holdable,
item_data.price,
item_data.barcode,
item_data.circ_modifier,
item_data.circ_as_type,
item_data.alert_message,
item_data.pub_note,
item_data.priv_note,
item_data.internal_id,
item_data.opac_visible,
item_data.stat_cat_data,
item_data.parts_data,
item_data.import_error,
item_data.error_detail
);
END LOOP;
RETURN NULL;
END;
zz_match_bibs_trigger
Function: vandelay.match_bib_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;
match_bucket INT;
BEGIN
IF TG_OP IN ('INSERT','UPDATE') AND NEW.imported_as IS NOT NULL THEN
RETURN NEW;
END IF;
DELETE FROM vandelay.bib_match WHERE queued_record = NEW.id;
SELECT q.match_set INTO match_set FROM vandelay.bib_queue q WHERE q.id = NEW.queue;
IF match_set IS NOT NULL THEN
NEW.quality := vandelay.measure_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 biblio.record_entry WHERE id = incoming_existing_id::bigint;
IF tmp_rec IS NOT NULL THEN
INSERT INTO vandelay.bib_match (queued_record, eg_record, match_score, quality)
SELECT
NEW.id,
b.id,
9999,
-- note: no match_set means quality==0
vandelay.measure_record_quality( b.marc, match_set )
FROM biblio.record_entry b
WHERE id = incoming_existing_id::bigint;
END IF;
END IF;
IF match_set IS NULL THEN
RETURN NEW;
END IF;
SELECT q.match_bucket INTO match_bucket FROM vandelay.bib_queue q WHERE q.id = NEW.queue;
FOR test_result IN SELECT * FROM
vandelay.match_set_test_marcxml(match_set, NEW.marc, match_bucket) LOOP
INSERT INTO vandelay.bib_match ( queued_record, eg_record, match_score, quality )
SELECT
NEW.id,
test_result.record,
test_result.quality,
vandelay.measure_record_quality( b.marc, match_set )
FROM biblio.record_entry b
WHERE id = test_result.record;
END LOOP;
RETURN NEW;
END;
Referenced By
The following tables have foreign keys pointing to vandelay.queued_bib_record (4 referencing table(s)):
| Table | Referencing Column(s) | Referenced Column(s) | Constraint |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|