How to query JIRA db by component in SQL?

linqiang September 3, 2012

I want to query jira issues by component in SQL, but i am surprised in the table of "jiraissue" , it is always NULL for the field of component,

What should i do in SQL? because we hope to know many metric by component.

thanks for your help

3 answers

1 accepted

10 votes
Answer accepted
Arthur Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 4, 2012

Hello,

You may use the following query to get the count of issues per components:

SELECT count(ji.id), c.cname FROM jiraissue ji 
INNER JOIN nodeassociation na ON ji.id = na.source_node_id
INNER JOIN component c ON na.sink_node_id = c.id
GROUP BY c.cname

I hope it helps! :)

Cheers!

linqiang September 4, 2012

thank you very much, it works. great!

Hoàng Nam May 26, 2014

Thanks so muchs

Xing Xin November 27, 2014

Slight tweak inner join nodeassociation na on ji.id = na.source_node_id and na.sink_node_entity = 'Component'

Like # people like this
Christian Olschinka December 12, 2019

Another consistent way (focussing on association_type) would be:

SELECT count(ji.id), c.cname FROM jiraissue ji 
INNER JOIN nodeassociation na ON ji.id = na.source_node_id
INNER JOIN component c ON na.sink_node_id = c.id
where na.association_type = 'IssueComponent'
GROUP BY c.cname;

The very first statement above may give wrong results from the nodeassociation table, where id of source and sink nodes match with issue and component id, but the association type does not (e.g. type IssueFixVersion instead of IssueComponent)., so I agree on Xing Xin's suggestion as a necessary supplement.

1 vote
LeahH December 2, 2016

What if you don't want a count and want to see the components in your results set from the jiraissue query?

Bhagya M S February 6, 2018

You can use the below query to fetch the components for a particular issue in JIRA

Please specify the valid jira issue key for below query:

note: in my case jira issue key is 'TEST-171'

SELECT
(case when (LENGTH(CM.CNAME)>0) then CM.CNAME else ' ' end) AS COMPONENT
FROM JIRAISSUE JI, Project P, COMPONENT CM, NODEASSOCIATION NA  where CM.PROJECT=P.ID AND JI.PROJECT = P.ID AND NA.SOURCE_NODE_ID=JI.ID AND NA.SINK_NODE_ID=CM.ID AND P.PKEY||'-'||JI.ISSUENUM= 'TEST-171'

0 votes
Pablo Beltran
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2015

 Alternatively, this is achievable with SQL for JIRA plugin too:

SELECT
    COUNT(*)
FROM
    PROJECTCOMPONENTS pc, ISSUECOMPONENTS ic
WHERE
    pc.id=ic.projectcomponentid

 

The major difference among both approaches would be that they would return the same result for the JIRA administrator whereas for the rest of the users, the SQL for JIRA plugin would return the amount of issues per component and counting only the issues that each user is granted to see in JIRA.

Suggest an answer

Log in or Sign up to answer