name volumes,
(SELECT XMLAGG(acn) FROM (
SELECT unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
- SELECT distinct acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ SELECT z.id, z.name, z.label_sortkey, z.pref_ou FROM
+ (SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
FROM asset.call_number acn
JOIN asset.copy acp ON (acn.id = acp.call_number)
- JOIN actor.org_unit_descendants( $2 ) aoud ON (acp.circ_lib = aoud.id)
- INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
+ JOIN actor.org_unit_descendants( $2 ) aou ON (acp.circ_lib = aou.id)
WHERE acn.record = $1
AND acn.deleted IS FALSE
AND acp.deleted IS FALSE
- ORDER BY pref_ou, aou.name, acn.label_sortkey
- LIMIT ($6 -> 'acn')::INT
- OFFSET ($7 -> 'acn')::INT
+ UNION
+ SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ FROM asset.call_number acn
+ INNER JOIN asset.uri_call_number_map auricnm ON acn.id = auricnm.call_number
+ INNER JOIN asset.uri auri ON auri.id = auricnm.uri
+ INNER JOIN actor.org_unit_ancestors( COALESCE($9, $2) ) aou ON (acn.owning_lib = aou.id)
+ WHERE acn.record = $1
+ AND acn.deleted IS FALSE
+ AND auri.active IS TRUE
+ ) AS z
+ ORDER BY z.pref_ou, z.name, z.label_sortkey
+ LIMIT ($6 -> 'acn')::INT
+ OFFSET ($7 -> 'acn')::INT
)y
)x)
)
name volumes,
(SELECT XMLAGG(acn) FROM (
SELECT unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
- SELECT distinct acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ SELECT z.id, z.name, z.label_sortkey, z.pref_ou FROM
+ (SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
FROM asset.call_number acn
JOIN asset.copy acp ON (acn.id = acp.call_number)
- JOIN actor.org_unit_descendants( $2, $4 ) aoud ON (acp.circ_lib = aoud.id)
- INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
+ JOIN actor.org_unit_descendants( $2, $4 ) aou ON (acp.circ_lib = aou.id)
WHERE acn.record = $1
AND acn.deleted IS FALSE
AND acp.deleted IS FALSE
- ORDER BY pref_ou, aou.name, acn.label_sortkey
- LIMIT ($6 -> 'acn')::INT
- OFFSET ($7 -> 'acn')::INT
+ UNION
+ SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ FROM asset.call_number acn
+ INNER JOIN asset.uri_call_number_map auricnm ON acn.id = auricnm.call_number
+ INNER JOIN asset.uri auri ON auri.id = auricnm.uri
+ INNER JOIN actor.org_unit_ancestors( COALESCE($9, $2) ) aou ON (acn.owning_lib = aou.id)
+ WHERE acn.record = $1
+ AND acn.deleted IS FALSE
+ AND auri.active IS TRUE
+ ) AS z
+ ORDER BY z.pref_ou, z.name, z.label_sortkey
+ LIMIT ($6 -> 'acn')::INT
+ OFFSET ($7 -> 'acn')::INT
)y
)x)
)
name volumes,
(SELECT XMLAGG(acn) FROM (
SELECT unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
- SELECT distinct acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ SELECT z.id, z.name, z.label_sortkey, z.pref_ou FROM
+ (SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
FROM asset.call_number acn
JOIN asset.copy acp ON (acn.id = acp.call_number)
- JOIN actor.org_unit_descendants( $2 ) aoud ON (acp.circ_lib = aoud.id)
- INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
+ JOIN actor.org_unit_descendants( $2 ) aou ON (acp.circ_lib = aou.id)
WHERE acn.record = $1
AND acn.deleted IS FALSE
AND acp.deleted IS FALSE
- ORDER BY pref_ou, aou.name, acn.label_sortkey
- LIMIT ($6 -> 'acn')::INT
- OFFSET ($7 -> 'acn')::INT
+ UNION
+ SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ FROM asset.call_number acn
+ INNER JOIN asset.uri_call_number_map auricnm ON acn.id = auricnm.call_number
+ INNER JOIN asset.uri auri ON auri.id = auricnm.uri
+ INNER JOIN actor.org_unit_ancestors( COALESCE($9, $2) ) aou ON (acn.owning_lib = aou.id)
+ WHERE acn.record = $1
+ AND acn.deleted IS FALSE
+ AND auri.active IS TRUE
+ ) AS z
+ ORDER BY z.pref_ou, z.name, z.label_sortkey
+ LIMIT ($6 -> 'acn')::INT
+ OFFSET ($7 -> 'acn')::INT
)y
)x)
)
name volumes,
(SELECT XMLAGG(acn) FROM (
SELECT unapi.acn(y.id,'xml','volume',evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'holdings_xml'),'bre'), $3, $4, $6, $7, FALSE) FROM (
- SELECT distinct acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ SELECT z.id, z.name, z.label_sortkey, z.pref_ou FROM
+ (SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
FROM asset.call_number acn
JOIN asset.copy acp ON (acn.id = acp.call_number)
- JOIN actor.org_unit_descendants( $2, $4 ) aoud ON (acp.circ_lib = aoud.id)
- INNER JOIN actor.org_unit aou ON (aou.id = acp.circ_lib)
+ JOIN actor.org_unit_descendants( $2, $4 ) aou ON (acp.circ_lib = aou.id)
WHERE acn.record = $1
AND acn.deleted IS FALSE
AND acp.deleted IS FALSE
- ORDER BY pref_ou, aou.name, acn.label_sortkey
- LIMIT ($6 -> 'acn')::INT
- OFFSET ($7 -> 'acn')::INT
+ UNION
+ SELECT acn.id, aou.name, acn.label_sortkey, evergreen.rank_ou(aou.id, COALESCE($9, $2), $2) AS pref_ou
+ FROM asset.call_number acn
+ INNER JOIN asset.uri_call_number_map auricnm ON acn.id = auricnm.call_number
+ INNER JOIN asset.uri auri ON auri.id = auricnm.uri
+ INNER JOIN actor.org_unit_ancestors( COALESCE($9, $2) ) aou ON (acn.owning_lib = aou.id)
+ WHERE acn.record = $1
+ AND acn.deleted IS FALSE
+ AND auri.active IS TRUE
+ ) AS z
+ ORDER BY z.pref_ou, z.name, z.label_sortkey
+ LIMIT ($6 -> 'acn')::INT
+ OFFSET ($7 -> 'acn')::INT
)y
)x)
)