<?xml version="1.0" encoding="UTF-8"?><database name="egdb3_12_9" schema="asset" type="PostgreSQL - 15.10 (Ubuntu 15.10-1.pgdg24.04+1)">
   <sequences>
      <sequence increment="1" name="call_number_class_id_seq" startValue="1"/>
      <sequence increment="1" name="call_number_id_seq" startValue="1"/>
      <sequence increment="1" name="call_number_note_id_seq" startValue="1"/>
      <sequence increment="1" name="call_number_prefix_id_seq" startValue="1"/>
      <sequence increment="1" name="call_number_suffix_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_alert_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_inventory_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_location_group_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_location_group_map_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_location_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_location_order_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_note_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_part_map_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_tag_copy_map_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_tag_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_template_id_seq" startValue="1"/>
      <sequence increment="1" name="copy_vis_attr_cache_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_course_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_course_materials_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_course_users_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_role_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_term_course_map_id_seq" startValue="1"/>
      <sequence increment="1" name="course_module_term_id_seq" startValue="1"/>
      <sequence increment="1" name="stat_cat_entry_copy_map_id_seq" startValue="1"/>
      <sequence increment="1" name="stat_cat_entry_id_seq" startValue="1"/>
      <sequence increment="1" name="stat_cat_entry_transparency_map_id_seq" startValue="1"/>
      <sequence increment="1" name="stat_cat_id_seq" startValue="1"/>
      <sequence increment="1" name="uri_call_number_map_id_seq" startValue="1"/>
      <sequence increment="1" name="uri_id_seq" startValue="1"/>
   </sequences>
   <tables>
      <table name="active_copy_alert" numRows="0" remarks="" schema="asset" type="VIEW" viewSql=" SELECT copy_alert.id,&#10;    copy_alert.alert_type,&#10;    copy_alert.copy,&#10;    copy_alert.temp,&#10;    copy_alert.create_time,&#10;    copy_alert.create_staff,&#10;    copy_alert.note,&#10;    copy_alert.ack_time,&#10;    copy_alert.ack_staff&#10;   FROM asset.copy_alert&#10;  WHERE (copy_alert.ack_time IS NULL);">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="id" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="alert_type" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="copy" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="temp" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="4" name="create_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="create_staff" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="note" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="7" name="ack_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="ack_staff" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
      </table>
      <table name="call_number" numRows="1822" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.call_number_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5">
            <child column="call_number" foreignKey="asset_call_number_note_record_fkey" implied="false" onDeleteCascade="true" schema="asset" table="call_number_note"/>
            <child column="call_number" foreignKey="asset_copy_call_number_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy"/>
            <child column="original_callnumber" foreignKey="course_module_course_materials_original_callnumber_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course_materials"/>
            <child column="call_number" foreignKey="uri_call_number_map_call_number_fkey" implied="false" onDeleteCascade="false" schema="asset" table="uri_call_number_map"/>
            <child column="target_call_number" foreignKey="call_number_bucket_item_target_call_number_fkey" implied="false" onDeleteCascade="true" schema="container" table="call_number_bucket_item"/>
            <child column="bind_call_number" foreignKey="distribution_bind_call_number_fkey" implied="false" onDeleteCascade="false" schema="serial" table="distribution"/>
            <child column="receive_call_number" foreignKey="distribution_receive_call_number_fkey" implied="false" onDeleteCascade="false" schema="serial" table="distribution"/>
            <child column="call_number" foreignKey="serial_unit_call_number_fkey" implied="false" onDeleteCascade="false" schema="serial" table="unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="creator" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_call_number_creator_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="2" name="create_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="editor" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_call_number_editor_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="4" name="edit_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="record" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_call_number_record_fkey" implied="false" onDeleteCascade="false" schema="biblio" table="record_entry"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="owning_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="asset_call_number_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="label" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="8" name="deleted" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="'-1'::integer" digits="0" id="9" name="prefix" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="call_number_prefix_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number_prefix"/>
         </column>
         <column autoUpdated="false" defaultValue="'-1'::integer" digits="0" id="10" name="suffix" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="call_number_suffix_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number_suffix"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="11" name="label_class" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="call_number_label_class_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number_class"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="12" name="label_sortkey" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="call_number_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_call_number_creator_idx" unique="false">
            <column ascending="true" name="creator"/>
         </index>
         <index name="asset_call_number_dewey_idx" unique="false"/>
         <index name="asset_call_number_editor_idx" unique="false">
            <column ascending="true" name="editor"/>
         </index>
         <index name="asset_call_number_label_once_per_lib" unique="true">
            <column ascending="true" name="record"/>
            <column ascending="true" name="owning_lib"/>
            <column ascending="true" name="label"/>
            <column ascending="true" name="prefix"/>
            <column ascending="true" name="suffix"/>
         </index>
         <index name="asset_call_number_label_sortkey" unique="false"/>
         <index name="asset_call_number_label_sortkey_browse" unique="false">
            <column ascending="true" name="id"/>
            <column ascending="true" name="owning_lib"/>
         </index>
         <index name="asset_call_number_record_idx" unique="false">
            <column ascending="true" name="record"/>
         </index>
         <index name="asset_call_number_upper_label_id_owning_lib_idx" unique="false">
            <column ascending="true" name="id"/>
            <column ascending="true" name="owning_lib"/>
         </index>
      </table>
      <table name="call_number_class" remarks="Defines the call number normalization database functions in the &quot;normalizer&quot;&#10;column and the tag/subfield combinations to use to lookup the call number in&#10;the &quot;field&quot; column for a given classification scheme. Tag/subfield combinations&#10;are delimited by commas." schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.call_number_class_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5">
            <child column="label_class" foreignKey="call_number_label_class_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="'asset.normalize_generic'::text" digits="0" id="2" name="normalizer" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="'050ab,055ab,060ab,070ab,080ab,082ab,086ab,088ab,090,092,096,098,099'::text" digits="0" id="3" name="field" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="call_number_class_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="call_number_note" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.call_number_note_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="call_number" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_call_number_note_record_fkey" implied="false" onDeleteCascade="true" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="creator" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_call_number_note_creator_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="3" name="create_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="pub" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="title" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="value" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="call_number_note_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_call_number_note_creator_idx" unique="false">
            <column ascending="true" name="creator"/>
         </index>
      </table>
      <table name="call_number_prefix" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.call_number_prefix_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="prefix" foreignKey="call_number_prefix_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owning_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="call_number_prefix_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="label" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="label_sortkey" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="call_number_prefix_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_call_number_prefix_once_per_lib" unique="true">
            <column ascending="true" name="label"/>
            <column ascending="true" name="owning_lib"/>
         </index>
         <index name="asset_call_number_prefix_sortkey_idx" unique="false">
            <column ascending="true" name="label_sortkey"/>
         </index>
      </table>
      <table name="call_number_suffix" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.call_number_suffix_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="suffix" foreignKey="call_number_suffix_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owning_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="call_number_suffix_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="label" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="label_sortkey" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="call_number_suffix_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_call_number_suffix_once_per_lib" unique="true">
            <column ascending="true" name="label"/>
            <column ascending="true" name="owning_lib"/>
         </index>
         <index name="asset_call_number_suffix_sortkey_idx" unique="false">
            <column ascending="true" name="label_sortkey"/>
         </index>
      </table>
      <table name="copy" numRows="4852" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5">
            <child column="item" foreignKey="course_module_course_materials_item_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course_materials"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="circ_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_circ_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="creator" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_copy_creator_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="call_number" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_copy_call_number_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="editor" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_copy_editor_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="5" name="create_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="6" name="edit_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="copy_number" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="0" digits="0" id="8" name="status" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_status_fkey" implied="false" onDeleteCascade="false" schema="config" table="copy_status"/>
         </column>
         <column autoUpdated="false" defaultValue="1" digits="0" id="9" name="location" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy_location"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="10" name="loan_duration" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="11" name="fine_level" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="12" name="age_protect" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="13" name="circulate" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="14" name="deposit" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="15" name="ref" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="16" name="holdable" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="0.00" digits="2" id="17" name="deposit_amount" nullable="false" remarks="" size="6" type="numeric" typeCode="2"/>
         <column autoUpdated="false" defaultValue="null" digits="2" id="18" name="price" nullable="true" remarks="" size="8" type="numeric" typeCode="2"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="19" name="barcode" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="20" name="circ_modifier" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="code" foreignKey="circ_mod_fkey" implied="false" onDeleteCascade="false" schema="config" table="circ_modifier"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="21" name="circ_as_type" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="22" name="dummy_title" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="23" name="dummy_author" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="24" name="alert_message" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="25" name="opac_visible" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="26" name="deleted" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="27" name="floating" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="asset_copy_floating_fkey" implied="false" onDeleteCascade="false" schema="config" table="floating_group"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="28" name="dummy_isbn" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="29" name="status_changed_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="30" name="active_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="31" name="mint_condition" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="2" id="32" name="cost" nullable="true" remarks="" size="8" type="numeric" typeCode="2"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="copy_barcode_key" unique="true">
            <column ascending="true" name="barcode"/>
         </index>
         <index name="cp_avail_cn_idx" unique="false">
            <column ascending="true" name="call_number"/>
         </index>
         <index name="cp_cn_idx" unique="false">
            <column ascending="true" name="call_number"/>
         </index>
         <index name="cp_create_date" unique="false">
            <column ascending="true" name="create_date"/>
         </index>
         <index name="cp_creator_idx" unique="false">
            <column ascending="true" name="creator"/>
         </index>
         <index name="cp_editor_idx" unique="false">
            <column ascending="true" name="editor"/>
         </index>
         <index name="cp_extant_by_circ_lib_idx" unique="false">
            <column ascending="true" name="circ_lib"/>
         </index>
         <checkConstraint constraint="((fine_level = ANY (ARRAY[1, 2, 3])))" name="copy_fine_level_check"/>
         <checkConstraint constraint="((loan_duration = ANY (ARRAY[1, 2, 3])))" name="copy_loan_duration_check"/>
      </table>
      <table name="copy_alert" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_alert_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="alert_type" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_alert_alert_type_fkey" implied="false" onDeleteCascade="true" schema="config" table="copy_alert_type"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="3" name="temp" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="4" name="create_time" nullable="false" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="create_staff" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="copy_alert_create_staff_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="note" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="7" name="ack_time" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="ack_staff" nullable="true" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="copy_alert_ack_staff_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_alert_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="copy_inventory" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_inventory_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="inventory_workstation" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_inventory_inventory_workstation_fkey" implied="false" onDeleteCascade="false" schema="actor" table="workstation"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="2" name="inventory_date" nullable="false" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_inventory_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_copy_inventory_date_once_per_copy" unique="true">
            <column ascending="true" name="inventory_date"/>
            <column ascending="true" name="copy"/>
         </index>
         <index name="copy_inventory_copy_idx" unique="false">
            <column ascending="true" name="copy"/>
         </index>
      </table>
      <table name="copy_location" numRows="89" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_location_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="location" foreignKey="distribution_formula_entry_location_fkey" implied="false" onDeleteCascade="false" schema="acq" table="distribution_formula_entry"/>
            <child column="location" foreignKey="lineitem_detail_location_fkey" implied="false" onDeleteCascade="false" schema="acq" table="lineitem_detail"/>
            <child column="copy_location" foreignKey="circulation_copy_location_fkey" implied="false" onDeleteCascade="false" schema="action" table="circulation"/>
            <child column="copy_location" foreignKey="actor_org_unit_proximity_copy_location_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit_proximity_adjustment"/>
            <child column="location" foreignKey="copy_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy"/>
            <child column="location" foreignKey="copy_location_group_map_location_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location_group_map"/>
            <child column="location" foreignKey="copy_location_order_location_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location_order"/>
            <child column="location" foreignKey="copy_template_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy_template"/>
            <child column="original_location" foreignKey="course_module_course_materials_original_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course_materials"/>
            <child column="copy_loc" foreignKey="circ_limit_set_copy_loc_map_copy_loc_fkey" implied="false" onDeleteCascade="true" schema="config" table="circ_limit_set_copy_loc_map"/>
            <child column="copy_location" foreignKey="circ_matrix_matchpoint_copy_location_fkey" implied="false" onDeleteCascade="false" schema="config" table="circ_matrix_matchpoint"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="owning_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="true" digits="0" id="3" name="holdable" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="hold_verify" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="5" name="opac_visible" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="6" name="circulate" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="label_prefix" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="label_suffix" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="9" name="checkin_alert" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="10" name="deleted" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="11" name="url" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_location_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="acl_name_once_per_lib" unique="true">
            <column ascending="true" name="name"/>
            <column ascending="true" name="owning_lib"/>
         </index>
      </table>
      <table name="copy_location_group" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_location_group_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="lgroup" foreignKey="copy_location_group_map_lgroup_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location_group_map"/>
            <child column="loc_grp_filter" foreignKey="badge_loc_grp_filter_fkey" implied="false" onDeleteCascade="false" schema="rating" table="badge"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_group_owner_fkey" implied="false" onDeleteCascade="true" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="0" digits="0" id="3" name="pos" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="top" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="5" name="opac_visible" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_location_group_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="lgroup_once_per_owner" unique="true">
            <column ascending="true" name="owner"/>
            <column ascending="true" name="name"/>
         </index>
      </table>
      <table name="copy_location_group_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_location_group_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="location" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_group_map_location_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="lgroup" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_group_map_lgroup_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location_group"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_location_group_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="lgroup_once_per_group" unique="true">
            <column ascending="true" name="lgroup"/>
            <column ascending="true" name="location"/>
         </index>
      </table>
      <table name="copy_location_order" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_location_order_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="location" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_order_location_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_location"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="org" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_location_order_org_fkey" implied="false" onDeleteCascade="true" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="0" digits="0" id="3" name="position" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_location_order_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="acplo_once_per_org" unique="true">
            <column ascending="true" name="location"/>
            <column ascending="true" name="org"/>
         </index>
      </table>
      <table name="copy_note" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_note_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owning_copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="creator" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="asset_copy_note_creator_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="3" name="create_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="pub" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="title" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="value" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_note_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_copy_note_creator_idx" unique="false">
            <column ascending="true" name="creator"/>
         </index>
         <index name="asset_copy_note_owning_copy_idx" unique="false">
            <column ascending="true" name="owning_copy"/>
         </index>
      </table>
      <table name="copy_part_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_part_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="target_copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="part" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_part_map_part_fkey" implied="false" onDeleteCascade="true" schema="biblio" table="monograph_part"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_part_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="copy_part_map_cp_part_idx" unique="true">
            <column ascending="true" name="target_copy"/>
            <column ascending="true" name="part"/>
         </index>
      </table>
      <table name="copy_tag" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_tag_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="tag" foreignKey="copy_tag_copy_map_tag_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_tag_copy_map"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="tag_type" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="code" foreignKey="copy_tag_tag_type_fkey" implied="false" onDeleteCascade="true" schema="config" table="copy_tag_type"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="label" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="value" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="index_vector" nullable="false" remarks="" size="2147483647" type="tsvector" typeCode="1111"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="staff_note" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="6" name="pub" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_tag_owner_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="url" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_tag_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_copy_tag_index_vector_idx" unique="false">
            <column ascending="true" name="index_vector"/>
         </index>
         <index name="asset_copy_tag_label_idx" unique="false">
            <column ascending="true" name="label"/>
         </index>
         <index name="asset_copy_tag_label_lower_idx" unique="false"/>
         <index name="asset_copy_tag_owner_idx" unique="false">
            <column ascending="true" name="owner"/>
         </index>
         <index name="asset_copy_tag_tag_type_idx" unique="false">
            <column ascending="true" name="tag_type"/>
         </index>
      </table>
      <table name="copy_tag_copy_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_tag_copy_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="copy" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="tag" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_tag_copy_map_tag_fkey" implied="false" onDeleteCascade="true" schema="asset" table="copy_tag"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_tag_copy_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_copy_tag_copy_map_copy_idx" unique="false">
            <column ascending="true" name="copy"/>
         </index>
         <index name="asset_copy_tag_copy_map_tag_idx" unique="false">
            <column ascending="true" name="tag"/>
         </index>
      </table>
      <table name="copy_template" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_template_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="bind_unit_template" foreignKey="distribution_bind_unit_template_fkey" implied="false" onDeleteCascade="false" schema="serial" table="distribution"/>
            <child column="receive_unit_template" foreignKey="distribution_receive_unit_template_fkey" implied="false" onDeleteCascade="false" schema="serial" table="distribution"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owning_lib" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_template_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="creator" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="copy_template_creator_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="editor" nullable="false" remarks="" size="19" type="int8" typeCode="-5">
            <parent column="id" foreignKey="copy_template_editor_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="4" name="create_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="now()" digits="6" id="5" name="edit_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="circ_lib" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_template_circ_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="status" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_template_status_fkey" implied="false" onDeleteCascade="false" schema="config" table="copy_status"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="9" name="location" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="copy_template_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy_location"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="10" name="loan_duration" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="11" name="fine_level" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="12" name="age_protect" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="13" name="circulate" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="14" name="deposit" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="15" name="ref" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="16" name="holdable" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="2" id="17" name="deposit_amount" nullable="true" remarks="" size="6" type="numeric" typeCode="2"/>
         <column autoUpdated="false" defaultValue="null" digits="2" id="18" name="price" nullable="true" remarks="" size="8" type="numeric" typeCode="2"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="19" name="circ_modifier" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="20" name="circ_as_type" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="21" name="alert_message" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="22" name="opac_visible" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="23" name="floating" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="asset_copy_template_floating_fkey" implied="false" onDeleteCascade="false" schema="config" table="floating_group"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="24" name="mint_condition" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_template_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <checkConstraint constraint="(((fine_level IS NULL) OR (fine_level = ANY (ARRAY[1, 2, 3]))))" name="valid_fine_level"/>
         <checkConstraint constraint="(((loan_duration IS NULL) OR (loan_duration = ANY (ARRAY[1, 2, 3]))))" name="valid_loan_duration"/>
      </table>
      <table name="copy_vis_attr_cache" numRows="4862" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.copy_vis_attr_cache_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="record" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="target_copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="vis_attr_vector" nullable="true" remarks="" size="10" type="_int4" typeCode="2003"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="copy_vis_attr_cache_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="copy_vis_attr_cache_copy_idx" unique="false">
            <column ascending="true" name="target_copy"/>
         </index>
         <index name="copy_vis_attr_cache_record_idx" unique="false">
            <column ascending="true" name="record"/>
         </index>
      </table>
      <table name="course_module_course" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_course_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="course" foreignKey="course_module_course_materials_course_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course_materials"/>
            <child column="course" foreignKey="course_module_course_users_course_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course_users"/>
            <child column="course" foreignKey="course_module_term_course_map_course_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_term_course_map"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="course_number" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="section_number" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="owning_lib" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="false" digits="0" id="5" name="is_archived" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_course_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="course_module_course_materials" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_course_materials_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="course" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_course_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="item" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_item_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="relationship" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="4" name="record" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_record_fkey" implied="false" onDeleteCascade="false" schema="biblio" table="record_entry"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="temporary_record" nullable="true" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="original_location" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_original_location_fkey" implied="false" onDeleteCascade="false" schema="asset" table="copy_location"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="7" name="original_status" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_original_status_fkey" implied="false" onDeleteCascade="false" schema="config" table="copy_status"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="8" name="original_circ_modifier" nullable="true" remarks="" size="2147483647" type="text" typeCode="12">
            <parent column="code" foreignKey="original_circ_mod_fkey" implied="false" onDeleteCascade="false" schema="config" table="circ_modifier"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="9" name="original_callnumber" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_original_callnumber_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="10" name="original_circ_lib" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_materials_original_circ_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_course_materials_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="course_module_course_materials_course_item_record_key" unique="true">
            <column ascending="true" name="course"/>
            <column ascending="true" name="item"/>
            <column ascending="true" name="record"/>
         </index>
      </table>
      <table name="course_module_course_users" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_course_users_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="course" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_users_course_fkey" implied="false" onDeleteCascade="false" schema="asset" table="course_module_course"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="usr" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_users_usr_fkey" implied="false" onDeleteCascade="false" schema="actor" table="usr"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="usr_role" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_course_users_usr_role_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_role"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_course_users_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="course_module_role" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_role_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="usr_role" foreignKey="course_module_course_users_usr_role_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_course_users"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="2" name="is_public" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_role_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="course_module_role_name_key" unique="true">
            <column ascending="true" name="name"/>
         </index>
      </table>
      <table name="course_module_term" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_term_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="term" foreignKey="course_module_term_course_map_term_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_term_course_map"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="owning_lib" nullable="true" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_term_owning_lib_fkey" implied="false" onDeleteCascade="false" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="6" id="3" name="start_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="4" name="end_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_term_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="cmt_once_per_owning_lib" unique="true">
            <column ascending="true" name="owning_lib"/>
            <column ascending="true" name="name"/>
         </index>
      </table>
      <table name="course_module_term_course_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.course_module_term_course_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="term" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_term_course_map_term_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_term"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="course" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="course_module_term_course_map_course_fkey" implied="false" onDeleteCascade="true" schema="asset" table="course_module_course"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="course_module_term_course_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="latest_inventory" numRows="0" remarks="" schema="asset" type="VIEW" viewSql=" SELECT DISTINCT ON (copy_inventory.copy) copy_inventory.id,&#10;    copy_inventory.inventory_workstation,&#10;    copy_inventory.inventory_date,&#10;    copy_inventory.copy&#10;   FROM asset.copy_inventory&#10;  ORDER BY copy_inventory.copy, copy_inventory.inventory_date DESC;">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="id" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="inventory_workstation" nullable="true" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="6" id="2" name="inventory_date" nullable="true" remarks="" size="35" type="timestamptz" typeCode="93"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="copy" nullable="true" remarks="" size="19" type="int8" typeCode="-5"/>
      </table>
      <table name="stat_cat" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.stat_cat_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="stat_cat" foreignKey="a_sce_sc_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat_entry"/>
            <child column="stat_cat" foreignKey="a_sc_sc_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat_entry_copy_map"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="a_sc_owner_fkey" implied="false" onDeleteCascade="true" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="false" digits="0" id="2" name="opac_visible" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="4" name="required" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="5" name="sip_field" nullable="true" remarks="" size="2" type="bpchar" typeCode="1">
            <parent column="field" foreignKey="stat_cat_sip_field_fkey" implied="false" onDeleteCascade="false" schema="asset" table="stat_cat_sip_fields"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="6" name="sip_format" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="7" name="checkout_archive" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="stat_cat_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="sc_once_per_owner" unique="true">
            <column ascending="true" name="owner"/>
            <column ascending="true" name="name"/>
         </index>
      </table>
      <table name="stat_cat_entry" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.stat_cat_entry_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="stat_cat_entry" foreignKey="a_sc_sce_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat_entry_copy_map"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="stat_cat" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="a_sce_sc_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="owner" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="a_sce_owner_fkey" implied="false" onDeleteCascade="true" schema="actor" table="org_unit"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="value" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="stat_cat_entry_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="sce_once_per_owner" unique="true">
            <column ascending="true" name="stat_cat"/>
            <column ascending="true" name="owner"/>
            <column ascending="true" name="value"/>
         </index>
      </table>
      <table name="stat_cat_entry_copy_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.stat_cat_entry_copy_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="stat_cat" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="a_sc_sc_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="stat_cat_entry" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="a_sc_sce_fkey" implied="false" onDeleteCascade="true" schema="asset" table="stat_cat_entry"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="owning_copy" nullable="false" remarks="" size="19" type="int8" typeCode="-5"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="stat_cat_entry_copy_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="sce_once_per_copy" unique="true">
            <column ascending="true" name="owning_copy"/>
            <column ascending="true" name="stat_cat"/>
         </index>
         <index name="scecm_owning_copy_idx" unique="false">
            <column ascending="true" name="owning_copy"/>
         </index>
      </table>
      <table name="stat_cat_entry_transparency_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.stat_cat_entry_transparency_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="stat_cat" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="stat_cat_entry" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="owning_transparency" nullable="false" remarks="" size="10" type="int4" typeCode="4"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="stat_cat_entry_transparency_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="scte_once_per_trans" unique="true">
            <column ascending="true" name="owning_transparency"/>
            <column ascending="true" name="stat_cat"/>
         </index>
      </table>
      <table name="stat_cat_sip_fields" remarks="Asset Statistical Category SIP Fields&#10;&#10;Contains the list of valid SIP Field identifiers for&#10;Statistical Categories." schema="asset" type="TABLE">
         <column autoUpdated="false" defaultValue="null" digits="0" id="0" name="field" nullable="false" remarks="" size="2" type="bpchar" typeCode="1">
            <child column="sip_field" foreignKey="stat_cat_sip_field_fkey" implied="false" onDeleteCascade="false" schema="asset" table="stat_cat"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="name" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="false" digits="0" id="2" name="one_only" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="field" sequenceNumberInPK="1"/>
         <index name="stat_cat_sip_fields_pkey" unique="true">
            <column ascending="true" name="field"/>
         </index>
      </table>
      <table name="uri" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.uri_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="10" type="serial" typeCode="4">
            <child column="uri" foreignKey="uri_call_number_map_uri_fkey" implied="false" onDeleteCascade="false" schema="asset" table="uri_call_number_map"/>
            <child column="uri" foreignKey="item_uri_fkey" implied="false" onDeleteCascade="false" schema="serial" table="item"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="href" nullable="false" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="label" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="3" name="use_restriction" nullable="true" remarks="" size="2147483647" type="text" typeCode="12"/>
         <column autoUpdated="false" defaultValue="true" digits="0" id="4" name="active" nullable="false" remarks="" size="1" type="bool" typeCode="-7"/>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="uri_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
      </table>
      <table name="uri_call_number_map" remarks="" schema="asset" type="TABLE">
         <column autoUpdated="true" defaultValue="nextval('asset.uri_call_number_map_id_seq'::regclass)" digits="0" id="0" name="id" nullable="false" remarks="" size="19" type="bigserial" typeCode="-5"/>
         <column autoUpdated="false" defaultValue="null" digits="0" id="1" name="uri" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="uri_call_number_map_uri_fkey" implied="false" onDeleteCascade="false" schema="asset" table="uri"/>
         </column>
         <column autoUpdated="false" defaultValue="null" digits="0" id="2" name="call_number" nullable="false" remarks="" size="10" type="int4" typeCode="4">
            <parent column="id" foreignKey="uri_call_number_map_call_number_fkey" implied="false" onDeleteCascade="false" schema="asset" table="call_number"/>
         </column>
         <primaryKey column="id" sequenceNumberInPK="1"/>
         <index name="uri_call_number_map_pkey" unique="true">
            <column ascending="true" name="id"/>
         </index>
         <index name="asset_uri_call_number_map_cn_idx" unique="false">
            <column ascending="true" name="call_number"/>
         </index>
         <index name="uri_cn_once" unique="true">
            <column ascending="true" name="uri"/>
            <column ascending="true" name="call_number"/>
         </index>
      </table>
   </tables>
   <routines>
      <routine dataAccess="MODIFIES" deterministic="false" name="acp_created()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    IF NEW.active_date IS NULL AND NEW.status IN (SELECT id FROM config.copy_status WHERE copy_active = true) THEN
        NEW.active_date := now();
    END IF;
    IF NEW.status_changed_time IS NULL THEN
        NEW.status_changed_time := now();
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="acp_location_fixer()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    new_copy_location INT;
BEGIN
    IF (TG_OP = 'UPDATE') THEN
        IF NEW.location = OLD.location AND NEW.call_number = OLD.call_number AND NEW.circ_lib = OLD.circ_lib THEN
            RETURN NEW;
        END IF;
    END IF;
    SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance((SELECT owning_lib FROM asset.call_number WHERE id = NEW.call_number)) aouad ON acpl.owning_lib = aouad.id WHERE deleted IS FALSE AND name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
    IF new_copy_location IS NULL THEN
        SELECT INTO new_copy_location acpl.id FROM asset.copy_location acpl JOIN actor.org_unit_ancestors_distance(NEW.circ_lib) aouad ON acpl.owning_lib = aouad.id WHERE deleted IS FALSE AND name = (SELECT name FROM asset.copy_location WHERE id = NEW.location) ORDER BY distance LIMIT 1;
    END IF;
    IF new_copy_location IS NOT NULL THEN
        NEW.location = new_copy_location;
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="acp_status_changed()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
	IF NEW.status <> OLD.status AND NOT (NEW.status = 0 AND OLD.status = 7) THEN
        NEW.status_changed_time := now();
        IF NEW.active_date IS NULL AND NEW.status IN (SELECT id FROM config.copy_status WHERE copy_active = true) THEN
            NEW.active_date := now();
        END IF;
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="all_visible_flags()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '(' || STRING_AGG(search.calculate_visibility_attribute(1 << x, 'copy_flags')::TEXT,'&') || ')'
      FROM  GENERATE_SERIES(0,0) AS x; -- increment as new flags are added.]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="autogenerate_placeholder_barcode()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
	IF NEW.barcode LIKE '@@%' THEN
		NEW.barcode := '@@' || NEW.id;
	END IF;
	RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="true" name="bib_source_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '(' || STRING_AGG(search.calculate_visibility_attribute(id, 'bib_source')::TEXT,'|') || ')'
      FROM  config.bib_source
      WHERE transcendant;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="cache_copy_visibility()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ocn     asset.call_number%ROWTYPE;
    ncn     asset.call_number%ROWTYPE;
    cid     BIGINT;
    dobib   BOOL;
BEGIN

    SELECT enabled = FALSE INTO dobib FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc';

    IF TG_TABLE_NAME = 'peer_bib_copy_map' THEN -- Only needs ON INSERT OR DELETE, so handle separately
        IF TG_OP = 'INSERT' THEN
            INSERT INTO asset.copy_vis_attr_cache (record, target_copy, vis_attr_vector) VALUES (
                NEW.peer_record,
                NEW.target_copy,
                asset.calculate_copy_visibility_attribute_set(NEW.target_copy)
            );

            RETURN NEW;
        ELSIF TG_OP = 'DELETE' THEN
            DELETE FROM asset.copy_vis_attr_cache
              WHERE record = OLD.peer_record AND target_copy = OLD.target_copy;

            RETURN OLD;
        END IF;
    END IF;

    IF TG_OP = 'INSERT' THEN -- Handles ON INSERT. ON UPDATE is below.
        IF TG_TABLE_NAME IN ('copy', 'unit') THEN
            SELECT * INTO ncn FROM asset.call_number cn WHERE id = NEW.call_number;
            INSERT INTO asset.copy_vis_attr_cache (record, target_copy, vis_attr_vector) VALUES (
                ncn.record,
                NEW.id,
                asset.calculate_copy_visibility_attribute_set(NEW.id)
            );
        ELSIF TG_TABLE_NAME = 'record_entry' THEN
            NEW.vis_attr_vector := biblio.calculate_bib_visibility_attribute_set(NEW.id, NEW.source, TRUE);
        ELSIF TG_TABLE_NAME = 'call_number' AND NEW.label = '##URI##' AND dobib THEN -- New located URI
            UPDATE  biblio.record_entry
              SET   vis_attr_vector = biblio.calculate_bib_visibility_attribute_set(NEW.record)
              WHERE id = NEW.record;

        END IF;

        RETURN NEW;
    END IF;

    -- handle items first, since with circulation activity
    -- their statuses change frequently
    IF TG_TABLE_NAME IN ('copy', 'unit') THEN -- This handles ON UPDATE OR DELETE. ON INSERT above

        IF TG_OP = 'DELETE' THEN -- Shouldn't get here, normally
            DELETE FROM asset.copy_vis_attr_cache WHERE target_copy = OLD.id;
            RETURN OLD;
        END IF;

        SELECT * INTO ncn FROM asset.call_number cn WHERE id = NEW.call_number;

        IF OLD.deleted <> NEW.deleted THEN
            IF NEW.deleted THEN
                DELETE FROM asset.copy_vis_attr_cache WHERE target_copy = OLD.id;
            ELSE
                INSERT INTO asset.copy_vis_attr_cache (record, target_copy, vis_attr_vector) VALUES (
                    ncn.record,
                    NEW.id,
                    asset.calculate_copy_visibility_attribute_set(NEW.id)
                );
            END IF;

            RETURN NEW;
        ELSIF OLD.location   <> NEW.location OR
            OLD.status       <> NEW.status OR
            OLD.opac_visible <> NEW.opac_visible OR
            OLD.circ_lib     <> NEW.circ_lib OR
            OLD.call_number  <> NEW.call_number
        THEN
            IF OLD.call_number  <> NEW.call_number THEN -- Special check since it's more expensive than the next branch
                SELECT * INTO ocn FROM asset.call_number cn WHERE id = OLD.call_number;

                IF ncn.record <> ocn.record THEN
                    -- We have to use a record-specific WHERE clause
                    -- to avoid modifying the entries for peer-bib copies.
                    UPDATE  asset.copy_vis_attr_cache
                      SET   target_copy = NEW.id,
                            record = ncn.record
                      WHERE target_copy = OLD.id
                            AND record = ocn.record;

                END IF;
            ELSE
                -- Any of these could change visibility, but
                -- we'll save some queries and not try to calculate
                -- the change directly.  We want to update peer-bib
                -- entries in this case, unlike above.
                UPDATE  asset.copy_vis_attr_cache
                  SET   target_copy = NEW.id,
                        vis_attr_vector = asset.calculate_copy_visibility_attribute_set(NEW.id)
                  WHERE target_copy = OLD.id;
            END IF;
        END IF;

    ELSIF TG_TABLE_NAME = 'call_number' THEN

        IF TG_OP = 'DELETE' AND OLD.label = '##URI##' AND dobib THEN -- really deleted located URI, if the delete protection rule is disabled...
            UPDATE  biblio.record_entry
              SET   vis_attr_vector = biblio.calculate_bib_visibility_attribute_set(OLD.record)
              WHERE id = OLD.record;
            RETURN OLD;
        END IF;

        IF OLD.label = '##URI##' AND dobib THEN -- Located URI
            IF OLD.deleted <> NEW.deleted OR OLD.record <> NEW.record OR OLD.owning_lib <> NEW.owning_lib THEN
                UPDATE  biblio.record_entry
                  SET   vis_attr_vector = biblio.calculate_bib_visibility_attribute_set(NEW.record)
                  WHERE id = NEW.record;

                IF OLD.record <> NEW.record THEN -- maybe on merge?
                    UPDATE  biblio.record_entry
                      SET   vis_attr_vector = biblio.calculate_bib_visibility_attribute_set(OLD.record)
                      WHERE id = OLD.record;
                END IF;
            END IF;

        ELSIF OLD.record <> NEW.record OR OLD.owning_lib <> NEW.owning_lib THEN
            UPDATE  asset.copy_vis_attr_cache
              SET   record = NEW.record,
                    vis_attr_vector = asset.calculate_copy_visibility_attribute_set(target_copy)
              WHERE target_copy IN (SELECT id FROM asset.copy WHERE call_number = NEW.id)
                    AND record = OLD.record;

        END IF;

    ELSIF TG_TABLE_NAME = 'record_entry' AND OLD.source IS DISTINCT FROM NEW.source THEN -- Only handles ON UPDATE, INSERT above
        NEW.vis_attr_vector := biblio.calculate_bib_visibility_attribute_set(NEW.id, NEW.source, TRUE);
    END IF;

    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="calculate_copy_visibility_attribute_set(copy_id bigint)" returnType="integer[]" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    copy_row    asset.copy%ROWTYPE;
    lgroup_map  asset.copy_location_group_map%ROWTYPE;
    attr_set    INT[] := '{}'::INT[];
BEGIN
    SELECT * INTO copy_row FROM asset.copy WHERE id = copy_id;

    attr_set := attr_set || search.calculate_visibility_attribute(copy_row.opac_visible::INT, 'copy_flags');
    attr_set := attr_set || search.calculate_visibility_attribute(copy_row.circ_lib, 'circ_lib');
    attr_set := attr_set || search.calculate_visibility_attribute(copy_row.status, 'status');
    attr_set := attr_set || search.calculate_visibility_attribute(copy_row.location, 'location');

    SELECT  ARRAY_APPEND(
                attr_set,
                search.calculate_visibility_attribute(owning_lib, 'owning_lib')
            ) INTO attr_set
      FROM  asset.call_number
      WHERE id = copy_row.call_number;

    FOR lgroup_map IN SELECT * FROM asset.copy_location_group_map WHERE location = copy_row.location LOOP
        attr_set := attr_set || search.calculate_visibility_attribute(lgroup_map.lgroup, 'location_group');
    END LOOP;

    RETURN attr_set;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="copy_id" type="bigint"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="check_delete_copy_location(acpl_id integer)" returnType="void" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    PERFORM TRUE FROM asset.copy WHERE location = acpl_id AND NOT deleted LIMIT 1;

    IF FOUND THEN
        RAISE EXCEPTION
            'Copy location % contains active copies and cannot be deleted', acpl_id;
    END IF;

    IF acpl_id = 1 THEN
        RAISE EXCEPTION
            'Copy location 1 cannot be deleted';
    END IF;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="acpl_id" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="circ_lib_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  * FROM asset.invisible_orgs('circ_lib');]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="copy_location_validate_edit()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    IF OLD.id = 1 THEN
        IF OLD.owning_lib != NEW.owning_lib OR NEW.deleted THEN
            RAISE EXCEPTION 'Copy location 1 cannot be moved or deleted';
        END IF;
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="copy_may_float_to_inventory_workstation()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    copy asset.copy%ROWTYPE;
    workstation actor.workstation%ROWTYPE;
BEGIN
    SELECT * INTO copy FROM asset.copy WHERE id = NEW.copy;
    IF FOUND THEN
        SELECT * INTO workstation FROM actor.workstation WHERE id = NEW.inventory_workstation;
        IF FOUND THEN
           IF copy.floating IS NULL THEN
              IF copy.circ_lib <> workstation.owning_lib THEN
                 RAISE EXCEPTION 'Inventory workstation owning lib (%) does not match copy circ lib (%).',
                       workstation.owning_lib, copy.circ_lib;
              END IF;
           ELSE
              IF NOT evergreen.can_float(copy.floating, copy.circ_lib, workstation.owning_lib) THEN
                 RAISE EXCEPTION 'Copy (%) cannot float to inventory workstation owning lib (%).',
                       copy.id, workstation.owning_lib;
              END IF;
           END IF;
        END IF;
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="copy_state(cid bigint)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    last_circ_stop	TEXT;
    the_copy	    asset.copy%ROWTYPE;
BEGIN

    SELECT * INTO the_copy FROM asset.copy WHERE id = cid;
    IF NOT FOUND THEN RETURN NULL; END IF;

    IF the_copy.status = 3 THEN -- Lost
        RETURN 'LOST';
    ELSIF the_copy.status = 4 THEN -- Missing
        RETURN 'MISSING';
    ELSIF the_copy.status = 14 THEN -- Damaged
        RETURN 'DAMAGED';
    ELSIF the_copy.status = 17 THEN -- Lost and paid
        RETURN 'LOST_AND_PAID';
    END IF;

    SELECT stop_fines INTO last_circ_stop
      FROM  action.circulation
      WHERE target_copy = cid AND checkin_time IS NULL
      ORDER BY xact_start DESC LIMIT 1;

    IF FOUND THEN
        IF last_circ_stop IN (
            'CLAIMSNEVERCHECKEDOUT',
            'CLAIMSRETURNED',
            'LONGOVERDUE'
        ) THEN
            RETURN last_circ_stop;
        END IF;
    END IF;

    RETURN 'NORMAL';
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="cid" type="bigint"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="invisible_orgs(otype text)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '!(' || STRING_AGG(search.calculate_visibility_attribute(id, $1)::TEXT,'|') || ')'
      FROM  actor.org_unit
      WHERE NOT opac_visible;]]></definition>
         <parameters>
            <parameter mode="IN" name="otype" type="text"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="label_normalizer()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    sortkey        TEXT := '';
BEGIN
    sortkey := NEW.label_sortkey;

    IF NEW.label_class IS NULL THEN
            NEW.label_class := COALESCE(
            (
                SELECT substring(value from E'\\d+')::integer
                FROM actor.org_unit_ancestor_setting('cat.default_classification_scheme', NEW.owning_lib)
            ), 1
        );
    END IF;

    EXECUTE 'SELECT ' || acnc.normalizer || '(' || 
       quote_literal( NEW.label ) || ')'
       FROM asset.call_number_class acnc
       WHERE acnc.id = NEW.label_class
       INTO sortkey;
    NEW.label_sortkey = sortkey;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="true" name="label_normalizer_dewey(text)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plperlu"><![CDATA[# Derived from the Koha C4::ClassSortRoutine::Dewey module
    # Copyright (C) 2007 LibLime
    # Licensed under the GPL v2 or later

    use strict;
    use warnings;

    my $init = uc(shift);
    $init =~ s/^\s+//;
    $init =~ s/\s+$//;
    $init =~ s!/!!g;
    $init =~ s/^([\p{IsAlpha}]+)/$1 /;
    my @tokens = split /\.|\s+/, $init;
    my $digit_group_count = 0;
    my $first_digit_group_idx;
    for (my $i = 0; $i <= $#tokens; $i++) {
        if ($tokens[$i] =~ /^\d+$/) {
            $digit_group_count++;
            if ($digit_group_count == 1) {
                $first_digit_group_idx = $i;
            }
            if (2 == $digit_group_count) {
                $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
                $tokens[$i] =~ tr/ /0/;
            }
        }
    }
    # Pad the first digit_group if there was only one
    if (1 == $digit_group_count) {
        $tokens[$first_digit_group_idx] .= '_000000000000000'
    }
    my $key = join("_", @tokens);
    $key =~ s/[^\p{IsAlnum}_]//g;

    return $key;]]></definition>
         <parameters>
            <parameter mode="IN" type="text"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="true" name="label_normalizer_generic(text)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plperlu"><![CDATA[# Created after looking at the Koha C4::ClassSortRoutine::Generic module,
    # thus could probably be considered a derived work, although nothing was
    # directly copied - but to err on the safe side of providing attribution:
    # Copyright (C) 2007 LibLime
    # Copyright (C) 2011 Equinox Software, Inc (Steve Callendar)
    # Licensed under the GPL v2 or later

    use strict;
    use warnings;

    # Converts the callnumber to uppercase
    # Strips spaces from start and end of the call number
    # Converts anything other than letters, digits, and periods into spaces
    # Collapses multiple spaces into a single underscore
    my $callnum = uc(shift);
    $callnum =~ s/^\s//g;
    $callnum =~ s/\s$//g;
    # NOTE: this previously used underscores, but this caused sorting issues
    # for the "before" half of page 0 on CN browse, sorting CNs containing a
    # decimal before "whole number" CNs
    $callnum =~ s/[^A-Z0-9_.]/ /g;
    $callnum =~ s/ {2,}/ /g;

    return $callnum;]]></definition>
         <parameters>
            <parameter mode="IN" type="text"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="true" name="label_normalizer_lc(text)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plperlu"><![CDATA[use strict;
    use warnings;

    # Library::CallNumber::LC is currently hosted at http://code.google.com/p/library-callnumber-lc/
    # The author hopes to upload it to CPAN some day, which would make our lives easier
    use Library::CallNumber::LC;

    my $callnum = Library::CallNumber::LC->new(shift);
    return $callnum->normalize();]]></definition>
         <parameters>
            <parameter mode="IN" type="text"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="location_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '!(' || STRING_AGG(search.calculate_visibility_attribute(id, 'location')::TEXT,'|') || ')'
      FROM  asset.copy_location
      WHERE NOT opac_visible;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="true" name="location_group_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT '!()'::TEXT; -- For now, as there's no way to cause a location group to hide all copies.
/*
    SELECT  '!(' || STRING_AGG(search.calculate_visibility_attribute(id, 'location_group')::TEXT,'|') || ')'
      FROM  asset.copy_location_group
      WHERE NOT opac_visible;
*/]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="luri_org_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  * FROM asset.invisible_orgs('luri_org');]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="merge_record_assets(target_record bigint, source_record bigint)" returnType="integer" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    moved_objects INT := 0;
    source_cn     asset.call_number%ROWTYPE;
    target_cn     asset.call_number%ROWTYPE;
    metarec       metabib.metarecord%ROWTYPE;
    hold          action.hold_request%ROWTYPE;
    ser_rec       serial.record_entry%ROWTYPE;
    ser_sub       serial.subscription%ROWTYPE;
    acq_lineitem  acq.lineitem%ROWTYPE;
    acq_request   acq.user_request%ROWTYPE;
    booking       booking.resource_type%ROWTYPE;
    source_part   biblio.monograph_part%ROWTYPE;
    target_part   biblio.monograph_part%ROWTYPE;
    multi_home    biblio.peer_bib_copy_map%ROWTYPE;
    uri_count     INT := 0;
    counter       INT := 0;
    uri_datafield TEXT;
    uri_text      TEXT := '';
BEGIN

    -- we don't merge bib -1
    IF target_record = -1 OR source_record = -1 THEN
       RETURN 0;
    END IF;

    -- move any 856 entries on records that have at least one MARC-mapped URI entry
    SELECT  INTO uri_count COUNT(*)
      FROM  asset.uri_call_number_map m
            JOIN asset.call_number cn ON (m.call_number = cn.id)
      WHERE cn.record = source_record;

    IF uri_count > 0 THEN
        
        -- This returns more nodes than you might expect:
        -- 7 instead of 1 for an 856 with $u $y $9
        SELECT  COUNT(*) INTO counter
          FROM  oils_xpath_table(
                    'id',
                    'marc',
                    'biblio.record_entry',
                    '//*[@tag="856"]',
                    'id=' || source_record
                ) as t(i int,c text);
    
        FOR i IN 1 .. counter LOOP
            SELECT  '<datafield xmlns="http://www.loc.gov/MARC21/slim"' || 
			' tag="856"' ||
			' ind1="' || FIRST(ind1) || '"'  ||
			' ind2="' || FIRST(ind2) || '">' ||
                        STRING_AGG(
                            '<subfield code="' || subfield || '">' ||
                            regexp_replace(
                                regexp_replace(
                                    regexp_replace(data,'&','&amp;','g'),
                                    '>', '&gt;', 'g'
                                ),
                                '<', '&lt;', 'g'
                            ) || '</subfield>', ''
                        ) || '</datafield>' INTO uri_datafield
              FROM  oils_xpath_table(
                        'id',
                        'marc',
                        'biblio.record_entry',
                        '//*[@tag="856"][position()=' || i || ']/@ind1|' ||
                        '//*[@tag="856"][position()=' || i || ']/@ind2|' ||
                        '//*[@tag="856"][position()=' || i || ']/*/@code|' ||
                        '//*[@tag="856"][position()=' || i || ']/*[@code]',
                        'id=' || source_record
                    ) as t(id int,ind1 text, ind2 text,subfield text,data text);

            -- As most of the results will be NULL, protect against NULLifying
            -- the valid content that we do generate
            uri_text := uri_text || COALESCE(uri_datafield, '');
        END LOOP;

        IF uri_text <> '' THEN
            UPDATE  biblio.record_entry
              SET   marc = regexp_replace(marc,'(</[^>]*record>)', uri_text || E'\\1')
              WHERE id = target_record;
        END IF;

    END IF;

	-- Find and move metarecords to the target record
	SELECT	INTO metarec *
	  FROM	metabib.metarecord
	  WHERE	master_record = source_record;

	IF FOUND THEN
		UPDATE	metabib.metarecord
		  SET	master_record = target_record,
			mods = NULL
		  WHERE	id = metarec.id;

		moved_objects := moved_objects + 1;
	END IF;

	-- Find call numbers attached to the source ...
	FOR source_cn IN SELECT * FROM asset.call_number WHERE record = source_record LOOP

		SELECT	INTO target_cn *
		  FROM	asset.call_number
		  WHERE	label = source_cn.label
            AND prefix = source_cn.prefix
            AND suffix = source_cn.suffix
			AND owning_lib = source_cn.owning_lib
			AND record = target_record
			AND NOT deleted;

		-- ... and if there's a conflicting one on the target ...
		IF FOUND THEN

			-- ... move the copies to that, and ...
			UPDATE	asset.copy
			  SET	call_number = target_cn.id
			  WHERE	call_number = source_cn.id;

			-- ... move V holds to the move-target call number
			FOR hold IN SELECT * FROM action.hold_request WHERE target = source_cn.id AND hold_type = 'V' LOOP
		
				UPDATE	action.hold_request
				  SET	target = target_cn.id
				  WHERE	id = hold.id;
		
				moved_objects := moved_objects + 1;
			END LOOP;
        
            UPDATE asset.call_number SET deleted = TRUE WHERE id = source_cn.id;

		-- ... if not ...
		ELSE
			-- ... just move the call number to the target record
			UPDATE	asset.call_number
			  SET	record = target_record
			  WHERE	id = source_cn.id;
		END IF;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find T holds targeting the source record ...
	FOR hold IN SELECT * FROM action.hold_request WHERE target = source_record AND hold_type = 'T' LOOP

		-- ... and move them to the target record
		UPDATE	action.hold_request
		  SET	target = target_record
		  WHERE	id = hold.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find serial records targeting the source record ...
	FOR ser_rec IN SELECT * FROM serial.record_entry WHERE record = source_record LOOP
		-- ... and move them to the target record
		UPDATE	serial.record_entry
		  SET	record = target_record
		  WHERE	id = ser_rec.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find serial subscriptions targeting the source record ...
	FOR ser_sub IN SELECT * FROM serial.subscription WHERE record_entry = source_record LOOP
		-- ... and move them to the target record
		UPDATE	serial.subscription
		  SET	record_entry = target_record
		  WHERE	id = ser_sub.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find booking resource types targeting the source record ...
	FOR booking IN SELECT * FROM booking.resource_type WHERE record = source_record LOOP
		-- ... and move them to the target record
		UPDATE	booking.resource_type
		  SET	record = target_record
		  WHERE	id = booking.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find acq lineitems targeting the source record ...
	FOR acq_lineitem IN SELECT * FROM acq.lineitem WHERE eg_bib_id = source_record LOOP
		-- ... and move them to the target record
		UPDATE	acq.lineitem
		  SET	eg_bib_id = target_record
		  WHERE	id = acq_lineitem.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find acq user purchase requests targeting the source record ...
	FOR acq_request IN SELECT * FROM acq.user_request WHERE eg_bib = source_record LOOP
		-- ... and move them to the target record
		UPDATE	acq.user_request
		  SET	eg_bib = target_record
		  WHERE	id = acq_request.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find parts attached to the source ...
	FOR source_part IN SELECT * FROM biblio.monograph_part WHERE record = source_record LOOP

		SELECT	INTO target_part *
		  FROM	biblio.monograph_part
		  WHERE	label = source_part.label
			AND record = target_record;

		-- ... and if there's a conflicting one on the target ...
		IF FOUND THEN

			-- ... move the copy-part maps to that, and ...
			UPDATE	asset.copy_part_map
			  SET	part = target_part.id
			  WHERE	part = source_part.id;

			-- ... move P holds to the move-target part
			FOR hold IN SELECT * FROM action.hold_request WHERE target = source_part.id AND hold_type = 'P' LOOP
		
				UPDATE	action.hold_request
				  SET	target = target_part.id
				  WHERE	id = hold.id;
		
				moved_objects := moved_objects + 1;
			END LOOP;

		-- ... if not ...
		ELSE
			-- ... just move the part to the target record
			UPDATE	biblio.monograph_part
			  SET	record = target_record
			  WHERE	id = source_part.id;
		END IF;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- Find multi_home items attached to the source ...
	FOR multi_home IN SELECT * FROM biblio.peer_bib_copy_map WHERE peer_record = source_record LOOP
		-- ... and move them to the target record
		UPDATE	biblio.peer_bib_copy_map
		  SET	peer_record = target_record
		  WHERE	id = multi_home.id;

		moved_objects := moved_objects + 1;
	END LOOP;

	-- And delete mappings where the item's home bib was merged with the peer bib
	DELETE FROM biblio.peer_bib_copy_map WHERE peer_record = (
		SELECT (SELECT record FROM asset.call_number WHERE id = call_number)
		FROM asset.copy WHERE id = target_copy
	);

    -- Apply merge tracking
    UPDATE biblio.record_entry 
        SET merge_date = NOW() WHERE id = target_record;

    UPDATE biblio.record_entry
        SET merge_date = NOW(), merged_to = target_record
        WHERE id = source_record;

    -- replace book bag entries of source_record with target_record
    UPDATE container.biblio_record_entry_bucket_item
        SET target_biblio_record_entry = target_record
        WHERE bucket IN (SELECT id FROM container.biblio_record_entry_bucket WHERE btype = 'bookbag')
        AND target_biblio_record_entry = source_record;

    -- move over record notes 
    UPDATE biblio.record_note 
        SET record = target_record, value = CONCAT(value,'; note merged from ',source_record::TEXT) 
        WHERE record = source_record
        AND NOT deleted;

    -- add note to record merge 
    INSERT INTO biblio.record_note (record, value) 
        VALUES (target_record,CONCAT('record ',source_record::TEXT,' merged on ',NOW()::TEXT));

    -- Finally, "delete" the source record
    UPDATE biblio.record_entry SET active = FALSE WHERE id = source_record;
    DELETE FROM biblio.record_entry WHERE id = source_record;

	-- That's all, folks!
	RETURN moved_objects;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="target_record" type="bigint"/>
            <parameter mode="IN" name="source_record" type="bigint"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="metarecord_copy_count(place integer, rid bigint, staff boolean)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    IF staff IS TRUE THEN
        IF place > 0 THEN
            RETURN QUERY SELECT * FROM asset.staff_ou_metarecord_copy_count( place, rid );
        ELSE
            RETURN QUERY SELECT * FROM asset.staff_lasso_metarecord_copy_count( -place, rid );
        END IF;
    ELSE
        IF place > 0 THEN
            RETURN QUERY SELECT * FROM asset.opac_ou_metarecord_copy_count( place, rid );
        ELSE
            RETURN QUERY SELECT * FROM asset.opac_lasso_metarecord_copy_count( -place, rid );
        END IF;
    END IF;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="place" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="IN" name="staff" type="boolean"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="metarecord_has_holdable_copy(rid bigint, ou integer DEFAULT NULL::integer)" returnType="boolean" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    PERFORM 1
        FROM
            asset.copy acp
            JOIN asset.call_number acn ON acp.call_number = acn.id
            JOIN asset.copy_location acpl ON acp.location = acpl.id
            JOIN config.copy_status ccs ON acp.status = ccs.id
            JOIN metabib.metarecord_source_map mmsm ON acn.record = mmsm.source
        WHERE
            mmsm.metarecord = rid
            AND acp.holdable = true
            AND acpl.holdable = true
            AND ccs.holdable = true
            AND acp.deleted = false
            AND acpl.deleted = false
            AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
        LIMIT 1;
    IF FOUND THEN
        RETURN true;
    END IF;
    RETURN FALSE;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="IN" name="ou" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="normalize_affix_sortkey()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    NEW.label_sortkey := REGEXP_REPLACE(
        evergreen.lpad_number_substrings(
            naco_normalize(NEW.label),
            '0',
            10
        ),
        E'\\s+',
        '',
        'g'
    );
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="opac_lasso_metarecord_copy_count(i_lasso integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) JOIN metabib.metarecord_source_map m ON (m.source = b.id) WHERE src.transcendant AND m.metarecord = rid;

    FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
        RETURN QUERY
        WITH org_list AS (SELECT ARRAY_AGG(id)::BIGINT[] AS orgs FROM actor.org_unit_descendants(ans.id) x),
             available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
             mask AS (SELECT c_attrs FROM asset.patron_default_visibility_mask() x)
        SELECT  -1,
                ans.id,
                COUNT( av.id ),
                SUM( (cp.status = ANY (available_statuses.ids))::INT ),
                COUNT( av.id ),
                trans
          FROM  mask,
                org_list,
                available_statuses,
                asset.copy_vis_attr_cache av
                JOIN asset.copy cp ON (cp.id = av.target_copy)
                JOIN metabib.metarecord_source_map m ON (m.metarecord = rid AND m.source = av.record)
          WHERE cp.circ_lib = ANY (org_list.orgs) AND av.vis_attr_vector @@ mask.c_attrs::query_int
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;   
                
    RETURN;     
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="i_lasso" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="opac_lasso_record_copy_count(i_lasso integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;

    FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
        RETURN QUERY
        WITH org_list AS (SELECT ARRAY_AGG(id)::BIGINT[] AS orgs FROM actor.org_unit_descendants(ans.id) x),
             available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
             mask AS (SELECT c_attrs FROM asset.patron_default_visibility_mask() x)
        SELECT  -1,
                ans.id,
                COUNT( av.id ),
                SUM( (cp.status = ANY (available_statuses.ids))::INT ),
                COUNT( av.id ),
                trans
          FROM  mask,
                org_list,
                asset.copy_vis_attr_cache av
                JOIN asset.copy cp ON (cp.id = av.target_copy AND av.record = rid)
          WHERE cp.circ_lib = ANY (org_list.orgs) AND av.vis_attr_vector @@ mask.c_attrs::query_int
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;   
                
    RETURN;     
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="i_lasso" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="opac_ou_metarecord_copy_count(org integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) JOIN metabib.metarecord_source_map m ON (m.source = b.id) WHERE src.transcendant AND m.metarecord = rid;

    FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
        RETURN QUERY
        WITH org_list AS (SELECT ARRAY_AGG(id)::BIGINT[] AS orgs FROM actor.org_unit_descendants(ans.id) x),
             available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
             mask AS (SELECT c_attrs FROM asset.patron_default_visibility_mask() x)
        SELECT  ans.depth,
                ans.id,
                COUNT( av.id ),
                SUM( (cp.status = ANY (available_statuses.ids))::INT ),
                COUNT( av.id ),
                trans
          FROM  mask,
                org_list,
                available_statuses,
                asset.copy_vis_attr_cache av
                JOIN asset.copy cp ON (cp.id = av.target_copy)
                JOIN metabib.metarecord_source_map m ON (m.metarecord = rid AND m.source = av.record)
          WHERE cp.circ_lib = ANY (org_list.orgs) AND av.vis_attr_vector @@ mask.c_attrs::query_int
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="org" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="opac_ou_record_copy_count(org integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;

    FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
        RETURN QUERY
        WITH org_list AS (SELECT ARRAY_AGG(id)::BIGINT[] AS orgs FROM actor.org_unit_descendants(ans.id) x),
             available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
             mask AS (SELECT c_attrs FROM asset.patron_default_visibility_mask() x)
        SELECT  ans.depth,
                ans.id,
                COUNT( av.id ),
                SUM( (cp.status = ANY (available_statuses.ids))::INT ),
                COUNT( av.id ),
                trans
          FROM  mask,
                available_statuses,
                org_list,
                asset.copy_vis_attr_cache av
                JOIN asset.copy cp ON (cp.id = av.target_copy AND av.record = rid)
                JOIN asset.call_number cn ON (cp.call_number = cn.id AND not cn.deleted)
          WHERE cp.circ_lib = ANY (org_list.orgs) AND av.vis_attr_vector @@ mask.c_attrs::query_int
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="org" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="owning_lib_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  * FROM asset.invisible_orgs('owning_lib');]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="patron_default_visibility_mask()" returnType="TABLE(b_attrs text, c_attrs text)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    copy_flags      TEXT; -- "c" attr

    owning_lib      TEXT; -- "c" attr
    circ_lib        TEXT; -- "c" attr
    status          TEXT; -- "c" attr
    location        TEXT; -- "c" attr
    location_group  TEXT; -- "c" attr

    luri_org        TEXT; -- "b" attr
    bib_sources     TEXT; -- "b" attr

    bib_tests       TEXT := '';
BEGIN
    copy_flags      := asset.all_visible_flags(); -- Will always have at least one

    owning_lib      := NULLIF(asset.owning_lib_default(),'!()');

    circ_lib        := NULLIF(asset.circ_lib_default(),'!()');
    status          := NULLIF(asset.status_default(),'!()');
    location        := NULLIF(asset.location_default(),'!()');
    location_group  := NULLIF(asset.location_group_default(),'!()');

    -- LURIs will be handled at the perl layer directly
    -- luri_org        := NULLIF(asset.luri_org_default(),'!()');
    bib_sources     := NULLIF(asset.bib_source_default(),'()');


    IF luri_org IS NOT NULL AND bib_sources IS NOT NULL THEN
        bib_tests := '('||ARRAY_TO_STRING( ARRAY[luri_org,bib_sources], '|')||')&('||luri_org||')&';
    ELSIF luri_org IS NOT NULL THEN
        bib_tests := luri_org || '&';
    ELSIF bib_sources IS NOT NULL THEN
        bib_tests := bib_sources || '|';
    END IF;

    RETURN QUERY SELECT bib_tests,
        '('||ARRAY_TO_STRING(
            ARRAY[copy_flags,owning_lib,circ_lib,status,location,location_group]::TEXT[],
            '&'
        )||')';
END;]]></definition>
         <parameters>
            <parameter mode="TABLE" name="b_attrs" type="text"/>
            <parameter mode="TABLE" name="c_attrs" type="text"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="record_copy_count(place integer, rid bigint, staff boolean)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    IF staff IS TRUE THEN
        IF place > 0 THEN
            RETURN QUERY SELECT * FROM asset.staff_ou_record_copy_count( place, rid );
        ELSE
            RETURN QUERY SELECT * FROM asset.staff_lasso_record_copy_count( -place, rid );
        END IF;
    ELSE
        IF place > 0 THEN
            RETURN QUERY SELECT * FROM asset.opac_ou_record_copy_count( place, rid );
        ELSE
            RETURN QUERY SELECT * FROM asset.opac_lasso_record_copy_count( -place, rid );
        END IF;
    END IF;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="place" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="IN" name="staff" type="boolean"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="record_has_holdable_copy(rid bigint, ou integer DEFAULT NULL::integer)" returnType="boolean" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    PERFORM 1
        FROM
            asset.copy acp
            JOIN asset.call_number acn ON acp.call_number = acn.id
            JOIN asset.copy_location acpl ON acp.location = acpl.id
            JOIN config.copy_status ccs ON acp.status = ccs.id
        WHERE
            acn.record = rid
            AND acp.holdable = true
            AND acpl.holdable = true
            AND ccs.holdable = true
            AND acp.deleted = false
            AND acpl.deleted = false
            AND acp.circ_lib IN (SELECT id FROM actor.org_unit_descendants(COALESCE($2,(SELECT id FROM evergreen.org_top()))))
        LIMIT 1;
    IF FOUND THEN
        RETURN true;
    END IF;
    RETURN FALSE;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="IN" name="ou" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="set_copy_tag_value()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[BEGIN
    IF NEW.value IS NULL THEN
        NEW.value = NEW.label;        
    END IF;

    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="staff_lasso_metarecord_copy_count(i_lasso integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) JOIN metabib.metarecord_source_map m ON (m.source = b.id) WHERE src.transcendant AND m.metarecord = rid;

    FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
        RETURN QUERY
        SELECT  -1,
                ans.id,
                COUNT( cp.id ),
                SUM( CASE WHEN cp.status IN (SELECT id FROM config.copy_status WHERE holdable AND is_available) THEN 1 ELSE 0 END ),
                COUNT( cp.id ),
                trans
          FROM
                actor.org_unit_descendants(ans.id) d
                JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
                JOIN asset.call_number cn ON (cn.id = cp.call_number AND NOT cn.deleted)
                JOIN metabib.metarecord_source_map m ON (m.metarecord = rid AND m.source = cn.record)
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="i_lasso" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="staff_lasso_record_copy_count(i_lasso integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;

    FOR ans IN SELECT u.org_unit AS id FROM actor.org_lasso_map AS u WHERE lasso = i_lasso LOOP
        RETURN QUERY
        SELECT  -1,
                ans.id,
                COUNT( cp.id ),
                SUM( CASE WHEN cp.status IN (SELECT id FROM config.copy_status WHERE holdable AND is_available)
                   THEN 1 ELSE 0 END ),
                SUM( CASE WHEN cl.opac_visible AND cp.opac_visible THEN 1 ELSE 0 END),
                trans
          FROM
                actor.org_unit_descendants(ans.id) d
                JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
                JOIN asset.copy_location cl ON (cp.location = cl.id AND NOT cl.deleted)
                JOIN asset.call_number cn ON (cn.record = rid AND cn.id = cp.call_number AND NOT cn.deleted)
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT -1, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="i_lasso" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="staff_ou_metarecord_copy_count(org integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE         
    ans RECORD; 
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) JOIN metabib.metarecord_source_map m ON (m.source = b.id) WHERE src.transcendant AND m.metarecord = rid;

    FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
        RETURN QUERY
        SELECT  ans.depth,
                ans.id,
                COUNT( cp.id ),
                SUM( CASE WHEN cp.status IN (SELECT id FROM config.copy_status WHERE holdable AND is_available) THEN 1 ELSE 0 END ),
                COUNT( cp.id ),
                trans
          FROM
                actor.org_unit_descendants(ans.id) d
                JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
                JOIN asset.call_number cn ON (cn.id = cp.call_number AND NOT cn.deleted)
                JOIN metabib.metarecord_source_map m ON (m.metarecord = rid AND m.source = cn.record)
          GROUP BY 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;

    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="org" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="staff_ou_record_copy_count(org integer, rid bigint)" returnType="TABLE(depth integer, org_unit integer, visible bigint, available bigint, unshadow bigint, transcendant integer)" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    ans RECORD;
    trans INT;
BEGIN
    SELECT 1 INTO trans FROM biblio.record_entry b JOIN config.bib_source src ON (b.source = src.id) WHERE src.transcendant AND b.id = rid;

    FOR ans IN SELECT u.id, t.depth FROM actor.org_unit_ancestors(org) AS u JOIN actor.org_unit_type t ON (u.ou_type = t.id) LOOP
        RETURN QUERY
        WITH available_statuses AS (SELECT ARRAY_AGG(id) AS ids FROM config.copy_status WHERE is_available),
            cp AS(
                SELECT  cp.id,
                        (cp.status = ANY (available_statuses.ids))::INT as available,
                        (cl.opac_visible AND cp.opac_visible)::INT as opac_visible
                  FROM
                        available_statuses,
                        actor.org_unit_descendants(ans.id) d
                        JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
                        JOIN asset.copy_location cl ON (cp.location = cl.id AND NOT cl.deleted)
                        JOIN asset.call_number cn ON (cn.record = rid AND cn.id = cp.call_number AND NOT cn.deleted)
            ),
            peer AS (
                select  cp.id,
                        (cp.status = ANY  (available_statuses.ids))::INT as available,
                        (cl.opac_visible AND cp.opac_visible)::INT as opac_visible
                FROM
                        available_statuses,
                        actor.org_unit_descendants(ans.id) d
                        JOIN asset.copy cp ON (cp.circ_lib = d.id AND NOT cp.deleted)
                        JOIN asset.copy_location cl ON (cp.location = cl.id AND NOT cl.deleted)
                        JOIN biblio.peer_bib_copy_map bp ON (bp.peer_record = rid AND bp.target_copy = cp.id)
            )
        select ans.depth, ans.id, count(id), sum(x.available::int), sum(x.opac_visible::int), trans
        from ((select * from cp) union (select * from peer)) x
        group by 1,2,6;

        IF NOT FOUND THEN
            RETURN QUERY SELECT ans.depth, ans.id, 0::BIGINT, 0::BIGINT, 0::BIGINT, trans;
        END IF;

    END LOOP;
    RETURN;
END;]]></definition>
         <parameters>
            <parameter mode="IN" name="org" type="integer"/>
            <parameter mode="IN" name="rid" type="bigint"/>
            <parameter mode="TABLE" name="depth" type="integer"/>
            <parameter mode="TABLE" name="org_unit" type="integer"/>
            <parameter mode="TABLE" name="visible" type="bigint"/>
            <parameter mode="TABLE" name="available" type="bigint"/>
            <parameter mode="TABLE" name="unshadow" type="bigint"/>
            <parameter mode="TABLE" name="transcendant" type="integer"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="stat_cat_check()" returnType="trigger" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="plpgsql"><![CDATA[DECLARE
    sipfield asset.stat_cat_sip_fields%ROWTYPE;
    use_count INT;
BEGIN
    IF NEW.sip_field IS NOT NULL THEN
        SELECT INTO sipfield * FROM asset.stat_cat_sip_fields WHERE field = NEW.sip_field;
        IF sipfield.one_only THEN
            SELECT INTO use_count count(id) FROM asset.stat_cat WHERE sip_field = NEW.sip_field AND id != NEW.id;
            IF use_count > 0 THEN
                RAISE EXCEPTION 'Sip field cannot be used twice';
            END IF;
        END IF;
    END IF;
    RETURN NEW;
END;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="status_default()" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '!(' || STRING_AGG(search.calculate_visibility_attribute(id, 'status')::TEXT,'|') || ')'
      FROM  config.copy_status
      WHERE NOT opac_visible;]]></definition>
         <parameters>
            <parameter mode="IN"/>
         </parameters>
      </routine>
      <routine dataAccess="MODIFIES" deterministic="false" name="visible_orgs(otype text)" returnType="text" securityType="INVOKER" type="FUNCTION">
         <comment/>
         <definition language="sql"><![CDATA[SELECT  '(' || STRING_AGG(search.calculate_visibility_attribute(id, $1)::TEXT,'|') || ')'
      FROM  actor.org_unit
      WHERE opac_visible;]]></definition>
         <parameters>
            <parameter mode="IN" name="otype" type="text"/>
         </parameters>
      </routine>
   </routines>
</database>
