Paste number 56160: very baseline staging example

Index of paste annotations: 1

Paste number 56160: very baseline staging example
Pasted by: miker_
When:1 year, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+17C0
Channel:#openils-evergreen
Paste contents:
Raw Source | XML | Display As
-- Given a staging table with the following structure ...

CREATE TABLE staging_items (
        callnum text, -- call number label
        catkey  int,  -- biblio.record_entry_id
        createdate      date,
        location        text,
        barcode         text,
        item_type       text,
        owning_lib      text  -- actor.org_unit.shortname
);

-- ... import using the following ...

-- First, we build shelving location
INSERT INTO asset.copy_location (name, owning_lib)
        SELECT  DISTINCT l.home_location, ou.id
          FROM  valdosta_items l JOIN actor.org_unit ou
                        ON (l.owning_lib = ou.shortname);

-- Import base copy data
INSERT INTO asset.copy (circ_lib,creator,editor,create_date,barcode,status,location,loan_duration,fine_level,circ_modifier,deposit,ref,call_number)
        SELECT  DISTINCT ou.id AS circ_lib,
                1 AS creator,
                1 AS editor,
                l.createdate AS create_date,
                l.barcode AS barcode,
                0 AS status,
                cl.id AS location,
                2 AS loan_duration,
                2 AS fine_level,
                CASE
                        WHEN l.item_type IN ('REFERENCE', 'DEPOSIT_BK') THEN 'BOOK'
                        ELSE l.item_type
                END AS circ_modifier,
                CASE
                        WHEN l.item_type = 'DEPOSIT_BK' THEN TRUE
                        ELSE FALSE
                END AS deposit,
                CASE
                        WHEN l.item_type = 'REFERENCE' THEN TRUE
                        ELSE FALSE
                END AS ref,
                cn.id AS call_number
          FROM  staging_items l
                JOIN actor.org_unit ou
                        ON (l.owning_lib = ou.shortname)
                JOIN asset.copy_location cl
                        ON (ou.id = cl.owning_lib AND l.home_location = cl.name)
                JOIN asset.call_number cn
                        ON (ou.id = cn.owning_lib AND l.catkey = cn.record AND l.callnum = cn.label);

Annotations for this paste:

Annotation number 1: call numbers
Pasted by: miker_
When:1 year, 4 months ago
Share:Tweet this! | http://paste.lisp.org/+17C0#1
Paste contents:
Raw Source | Display As
INSERT INTO asset.call_number (creator,editor,record,label,owning_lib)
        SELECT  DISTINCT 1, 1, l.catkey , l.callnum, ou.id
          FROM  valdosta_items l
                JOIN biblio.record_entry b ON (l.catkey = b.id)
                JOIN actor.org_unit ou ON (l.owning_lib = ou.shortname);

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.