acq.lineitem
|
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('acq.lineitem_id_seq'::regclass) |
|
creator FK |
|
No |
||
editor FK |
|
No |
||
selector FK |
|
No |
||
provider FK |
|
Yes |
||
purchase_order FK |
|
Yes |
||
picklist FK |
|
Yes |
||
expected_recv_time |
|
Yes |
||
create_time |
|
No |
now() |
|
edit_time |
|
No |
now() |
|
marc |
|
No |
||
eg_bib_id FK |
|
Yes |
||
source_label |
|
Yes |
||
state |
|
No |
'new'::text |
|
cancel_reason FK |
|
Yes |
||
estimated_unit_price |
|
Yes |
||
claim_policy FK |
|
Yes |
||
queued_record FK |
|
Yes |
Foreign Keys
| Column(s) | References | On Delete | On Update | Deferrable | Constraint |
|---|---|---|---|---|---|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
|
|
SET NULL |
NO ACTION |
DEFERRED |
|
|
|
NO ACTION |
NO ACTION |
DEFERRED |
|
Indexes
| Index | Method | Definition |
|---|---|---|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
Triggers
| Trigger | Timing | Event | Level | Function |
|---|---|---|---|---|
|
AFTER |
DELETE OR UPDATE |
ROW |
|
|
BEFORE |
DELETE OR UPDATE |
ROW |
|
|
AFTER |
INSERT OR UPDATE |
ROW |
Trigger Bodies
audit_acq_lineitem_update_trigger
Function: acq.audit_acq_lineitem_func()
Timing: AFTER DELETE OR UPDATE ROW
BEGIN
INSERT INTO acq.acq_lineitem_history
SELECT nextval('acq.acq_lineitem_pkey_seq'),
now(),
SUBSTR(TG_OP,1,1),
OLD.*;
RETURN NULL;
END;
cleanup_lineitem_trigger
Function: public.cleanup_acq_marc()
Timing: BEFORE DELETE OR UPDATE ROW
BEGIN
IF TG_OP = 'UPDATE' THEN
DELETE FROM acq.lineitem_attr
WHERE lineitem = OLD.id AND attr_type IN ('lineitem_provider_attr_definition', 'lineitem_marc_attr_definition','lineitem_generated_attr_definition');
RETURN NEW;
ELSE
DELETE FROM acq.lineitem_attr WHERE lineitem = OLD.id;
RETURN OLD;
END IF;
END;
ingest_lineitem_trigger
Function: public.ingest_acq_marc()
Timing: AFTER INSERT OR UPDATE ROW
DECLARE
value TEXT;
atype TEXT;
prov INT;
pos INT;
adef RECORD;
xpath_string TEXT;
BEGIN
FOR adef IN SELECT *,tableoid FROM acq.lineitem_attr_definition LOOP
SELECT relname::TEXT INTO atype FROM pg_class WHERE oid = adef.tableoid;
IF (atype NOT IN ('lineitem_usr_attr_definition','lineitem_local_attr_definition')) THEN
IF (atype = 'lineitem_provider_attr_definition') THEN
SELECT provider INTO prov FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
CONTINUE WHEN NEW.provider IS NULL OR prov <> NEW.provider;
END IF;
IF (atype = 'lineitem_provider_attr_definition') THEN
SELECT xpath INTO xpath_string FROM acq.lineitem_provider_attr_definition WHERE id = adef.id;
ELSIF (atype = 'lineitem_marc_attr_definition') THEN
SELECT xpath INTO xpath_string FROM acq.lineitem_marc_attr_definition WHERE id = adef.id;
ELSIF (atype = 'lineitem_generated_attr_definition') THEN
SELECT xpath INTO xpath_string FROM acq.lineitem_generated_attr_definition WHERE id = adef.id;
END IF;
xpath_string := REGEXP_REPLACE(xpath_string,$re$//?text\(\)$$re$,'');
IF (adef.code = 'title' OR adef.code = 'author') THEN
-- title and author should not be split
-- FIXME: once oils_xpath can grok XPATH 2.0 functions, we can use
-- string-join in the xpath and remove this special case
SELECT extract_acq_marc_field(id, xpath_string, adef.remove) INTO value FROM acq.lineitem WHERE id = NEW.id;
IF (value IS NOT NULL AND value <> '') THEN
INSERT INTO acq.lineitem_attr (lineitem, definition, attr_type, attr_name, attr_value)
VALUES (NEW.id, adef.id, atype, adef.code, value);
END IF;
ELSE
pos := 1;
LOOP
-- each application of the regex may produce multiple values
FOR value IN
SELECT * FROM extract_acq_marc_field_set(
NEW.id, xpath_string || '[' || pos || ']', adef.remove)
LOOP
IF (value IS NOT NULL AND value <> '') THEN
INSERT INTO acq.lineitem_attr
(lineitem, definition, attr_type, attr_name, attr_value)
VALUES (NEW.id, adef.id, atype, adef.code, value);
ELSE
EXIT;
END IF;
END LOOP;
IF NOT FOUND THEN
EXIT;
END IF;
pos := pos + 1;
END LOOP;
END IF;
END IF;
END LOOP;
RETURN NULL;
END;
Referenced By
The following tables have foreign keys pointing to acq.lineitem (7 referencing table(s)):
| Table | Referencing Column(s) | Referenced Column(s) | Constraint |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|