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: queued_bib_record_bib_source_fkey, queued_bib_record_import_error_fkey, queued_bib_record_imported_as_fkey, queued_bib_record_queue_fkey.

Trigger Side Effects: Writing to this table automatically triggers writes to other tables:

Columns

Column Type Nullable Default Notes

id PK

bigint

No

nextval('vandelay.queued_record_id_seq'::regclass)

create_time

timestamp with time zone

No

now()

import_time

timestamp with time zone

Yes

purpose

text

No

'import'::text

marc

text

No

quality

integer

No

0

queue FK

integer

No

vandelay.bib_queue(id)

bib_source FK

integer

Yes

config.bib_source(id)

imported_as FK

bigint

Yes

biblio.record_entry(id)

import_error FK

text

Yes

vandelay.import_error(code)

error_detail

text

Yes

Primary Key

(id)

Foreign Keys

Column(s) References On Delete On Update Deferrable Constraint

bib_source

config.bib_source(id)

NO ACTION

NO ACTION

DEFERRED

queued_bib_record_bib_source_fkey

import_error

vandelay.import_error(code)

SET NULL

CASCADE

DEFERRED

queued_bib_record_import_error_fkey

imported_as

biblio.record_entry(id)

NO ACTION

NO ACTION

DEFERRED

queued_bib_record_imported_as_fkey

queue

vandelay.bib_queue(id)

CASCADE

NO ACTION

DEFERRED

queued_bib_record_queue_fkey

Check Constraints

  • queued_record_purpose_check: CHECK purpose = ANY (ARRAY['import'::text, 'overlay'::text])

Indexes

Index Method Definition

queued_bib_record_pkey PK

btree

CREATE UNIQUE INDEX queued_bib_record_pkey ON vandelay.queued_bib_record USING btree (id)

queued_bib_record_queue_idx

btree

CREATE INDEX queued_bib_record_queue_idx ON vandelay.queued_bib_record USING btree (queue)

Triggers

Trigger Timing Event Level Function

cleanup_bib_trigger

BEFORE

DELETE OR UPDATE

ROW

vandelay.cleanup_bib_marc()

ingest_bib_trigger

AFTER

INSERT OR UPDATE

ROW

vandelay.ingest_bib_marc()

ingest_item_trigger

AFTER

INSERT OR UPDATE

ROW

vandelay.ingest_bib_items()

zz_match_bibs_trigger

BEFORE

INSERT OR UPDATE

ROW

vandelay.match_bib_record()

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 NEW).

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 NEW).

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

acq.lineitem

queued_record

id

lineitem_queued_record_fkey

vandelay.bib_match

queued_record

id

bib_match_queued_record_fkey

vandelay.import_item

record

id

import_item_record_fkey

vandelay.queued_bib_record_attr

record

id

queued_bib_record_attr_record_fkey