Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

SQL Server Script for Locating Attachments

Amy Carey April 7, 2022

Would like query for SQL Server to locate attachments. Was provided the below. Will either of these work for SQL Server?

MYSQL

 selectc.TITLE as "Attachment Name", cp.LONGVAL as "File Size",c2.TITLE as "Page Title", s.SPACENAME as "Space Name", concat("http://<confluence_base_url>/pages/viewpageattachments.action?pageId=", c.PAGEID) as "Location"from CONTENT cjoin CONTENT c2 on c.PAGEID = c2.CONTENTIDjoin CONTENTPROPERTIES cp on c.CONTENTID = cp.CONTENTIDjoin SPACES s on c2.SPACEID = s.SPACEID where c.CONTENTTYPE = 'ATTACHMENT' and cp.PROPERTYNAME = 'FILESIZE'order by cp.LONGVAL desc;

POSTGRESQL

 select c.TITLE as Attachment_Name, cp.LONGVAL as Attachment_Size, s.spacename,c2.TITLE as Page_Title,'http://<confluence_base_url>/pages/viewpageattachments.action?pageId='||c.PAGEID as Locationfrom CONTENT cjoin CONTENT c2 ON c.PAGEID = c2.CONTENTIDjoin CONTENTPROPERTIES cp on c.CONTENTID = cp.CONTENTIDjoin SPACES s on c2.SPACEID = s.SPACEIDwhere c.CONTENTTYPE = 'ATTACHMENT' and cp.PROPERTYNAME = 'FILESIZE'order by cp.LONGVAL desc;

Replace <confluence_base_url> with your Confluence Base URL . This was tested against MySQL and PostgreSQL.

1 answer

0 votes
Thiago Masutti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 9, 2022

Hi @Amy Carey 

I believe the query for MySQL should work fine on MS SQL Server.

The only function there is CONCAT which has the same syntax on SQL Server.

Let us know if you get any error when running it.

Kind regards,
Thiago Masutti

Amy Carey April 20, 2022

Thank you Thiago. We'd like to also add the path and last modified date. How may the query be updated to include that information?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events