acq.purchase_order
|
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. |
|
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.purchase_order_id_seq'::regclass) |
|
owner FK |
|
No |
||
creator FK |
|
No |
||
editor FK |
|
No |
||
ordering_agency FK |
|
No |
||
create_time |
|
No |
now() |
|
edit_time |
|
No |
now() |
|
provider FK |
|
No |
||
state |
|
No |
'new'::text |
|
order_date |
|
Yes |
||
name |
|
No |
||
cancel_reason FK |
|
Yes |
||
prepayment_required |
|
No |
false |
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 |
|
Check Constraints
-
valid_po_state:CHECK state = ANY (ARRAY['new'::text, 'pending'::text, 'on-order'::text, 'received'::text, 'cancelled'::text])
Indexes
| Index | Method | Definition |
|---|---|---|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
|
btree |
|
Triggers
| Trigger | Timing | Event | Level | Function |
|---|---|---|---|---|
|
AFTER |
DELETE OR UPDATE |
ROW |
|
|
BEFORE |
INSERT OR UPDATE |
ROW |
|
|
BEFORE |
INSERT OR UPDATE |
ROW |
Trigger Bodies
audit_acq_purchase_order_update_trigger
Function: acq.audit_acq_purchase_order_func()
Timing: AFTER DELETE OR UPDATE ROW
BEGIN
INSERT INTO acq.acq_purchase_order_history
SELECT nextval('acq.acq_purchase_order_pkey_seq'),
now(),
SUBSTR(TG_OP,1,1),
OLD.*;
RETURN NULL;
END;
po_name_default_trg
Function: acq.purchase_order_name_default()
Timing: BEFORE INSERT OR UPDATE ROW
|
This trigger modifies the row before it is written (returns a modified |
BEGIN
IF NEW.name IS NULL THEN
NEW.name := NEW.id::TEXT;
END IF;
RETURN NEW;
END;
po_org_name_date_unique_trg
Function: acq.po_org_name_date_unique()
Timing: BEFORE INSERT OR UPDATE ROW
|
This trigger modifies the row before it is written (returns a modified |
DECLARE
collision INT;
BEGIN
--
-- If order_date is not null, then make sure we don't have a collision
-- on order_date (truncated to day), org, and name
--
IF NEW.order_date IS NULL THEN
RETURN NEW;
END IF;
--
-- In the WHERE clause, we compare the order_dates without regard to time of day.
-- We use a pair of inequalities instead of comparing truncated dates so that the
-- query can do an indexed range scan.
--
SELECT 1 INTO collision
FROM acq.purchase_order
WHERE
ordering_agency = NEW.ordering_agency
AND name = NEW.name
AND order_date >= date_trunc( 'day', NEW.order_date )
AND order_date < date_trunc( 'day', NEW.order_date ) + '1 day'::INTERVAL
AND id <> NEW.id;
--
IF collision IS NULL THEN
-- okay, no collision
RETURN NEW;
ELSE
-- collision; nip it in the bud
RAISE EXCEPTION 'Colliding purchase orders: ordering_agency %, date %, name ''%''',
NEW.ordering_agency, NEW.order_date, NEW.name;
END IF;
END;
Referenced By
The following tables have foreign keys pointing to acq.purchase_order (6 referencing table(s)):
| Table | Referencing Column(s) | Referenced Column(s) | Constraint |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|