DSpace SQL Snippets
Posted On June 3, 2014
Here are some SQL queries you can copy and paste into DSpace.
-
- Select/update the access policy to Anonymous for all thumbnails that have their group set as 2 (e.g. anu-archives) :
1234567891011UPDATE resourcepolicySET epersongroup_id = 0--select count('x') from resourcepolicyWHERE epersongroup_id = 2AND policy_id IN (SELECT rp.policy_idFROM resourcepolicy rp,bundle2bitstream bb,bundle bWHERE b.NAME = 'THUMBNAIL'AND b.bundle_id = bb.bundle_idAND bb.bitstream_id = rp.resource_id);Or do an individual one by adding:
1and rp.policy_id=1234567where that ID is found on the authorisations page in the Full Item Record view.
Change the above to BRANDED_PREVIEW to affect the permissions on those as well.
Remove this SQL from the above to affect ALL thumbnails/previews, not just those in group
- Find all items that have their original bitstream open to the public:
1234567891011121314151617181920212223SELECT bits.name,c.name,h.handleFROM bitstream bits,bundle2bitstream b2b,bundle buns,resourcepolicy rp,item2bundle i2b,item i,collection2item c2i,collection c,handle hWHERE bits.bitstream_id = b2b.bitstream_idAND buns.bundle_id = b2b.bundle_idAND rp.resource_id = b2b.bitstream_idAND i2b.bundle_id = b2b.bundle_idAND i.item_id = i2b.item_idAND c2i.collection_id = i.owning_collectionAND c.collection_id = c2i.collection_idAND buns.name = 'ORIGINAL'AND rp.epersongroup_id = '0'AND h.resource_id = buns.bundle_idLIMIT 1000000
NB. This needs tweaking:
- Using subselects to filter results for various conditions:
This SQL selects the relation.ispartof field (42) for all handles in the sub query (i.e. the ones that have NARU in the affiliation field (121)).
12345678910111213141516SELECT handle,text_valueFROM handle,metadatavalueWHERE metadatavalue.metadata_field_id = 42AND metadatavalue.item_id = handle.resource_idAND handle.handle IN (SELECT handleFROM handle,item,metadatavalueWHERE metadatavalue.item_id = handle.resource_idAND metadatavalue.metadata_field_id = 121AND handle.resource_type_id = 2AND handle.resource_id = item.item_idAND text_value LIKE '%NARU%'ORDER BY text_value) - Find massive files:
12345SELECT *FROM bitstreamWHERE deleted = falseORDER BY size_bytes DESCLIMIT 10
Get the handle of these big files:
12345678910111213SELECT h.handle,b.size_bytes,b.nameFROM bitstream b,bundle2bitstream b2b,item2bundle i2b,handle hWHERE b2b.bitstream_id = b.bitstream_idAND b2b.bundle_id = i2b.bundle_idAND i2b.item_id = h.resource_idAND b.deleted = falseORDER BY b.size_bytes DESCLIMIT 2 - Find all handles that correspond to a specific Metadata Field within a given collection:
123456789101112SELECT DISTINCT handle,metadatavalue.text_valueFROM handle,item,metadatavalueWHERE metadatavalue.item_id = handle.resource_idAND metadata_field_id = 121AND handle.resource_type_id = 2AND item.withdrawn = 'f'AND handle.resource_id = item.item_idAND item.owning_collection = '107'ORDER BY handle
- Select/update the access policy to Anonymous for all thumbnails that have their group set as 2 (e.g. anu-archives) :
One Comment
Hi
Can you come up with a code that will generate all metadata values i.e author, subject, title, citation all the fields