@@ -3,7 +3,11 @@ CREATE OR REPLACE FUNCTION get_pedigree(
3
3
" germplasmDbId" text
4
4
)
5
5
RETURNS json AS $$
6
+ DECLARE
7
+ pedigree_node_id text ;
6
8
BEGIN
9
+ SELECT id INTO pedigree_node_id FROM pedigree_node WHERE germplasm_id = " germplasmDbId" ;
10
+
7
11
RETURN (
8
12
SELECT json_build_object(
9
13
' @context' , ' []' ::json,
@@ -15,49 +19,57 @@ BEGIN
15
19
' familyCode' , node .family_code ,
16
20
' germplasmDbId' , " germplasmDbId" ,
17
21
' germplasmName' , germ .germplasm_name ,
18
- ' parents' , json_agg (
22
+ ' parents' , COALESCE (
19
23
(
20
- SELECT json_build_object(
21
- ' germplasmDbId' , parent .id ,
22
- ' germplasmName' , parent .germplasm_name ,
23
- ' parentType' , to_parent_type(e .parent_type )
24
- )
24
+ SELECT
25
+ json_agg(
26
+ json_build_object(
27
+ ' germplasmDbId' , parent .id ,
28
+ ' germplasmName' , parent .germplasm_name ,
29
+ ' parentType' , to_parent_type(e .parent_type )
30
+ )
31
+ )
25
32
FROM
26
33
pedigree_node parent_node
27
34
JOIN
28
- pedigree_edge e ON parent_node .id = e .connceted_node_id AND e .edge_type = edge_type_to_int(' parent' ) -- TODO: hardcoded EdgeType (parent=0, child=1, sibling=2)
35
+ pedigree_edge e ON parent_node .id = e .connceted_node_id AND e .edge_type = edge_type_to_int(' parent' )
29
36
JOIN
30
37
germplasm parent ON parent_node .germplasm_id = parent .id
31
- WHERE e .this_node_id = (SELECT child_node .id
38
+ WHERE
39
+ e .this_node_id = (SELECT child_node .id
32
40
FROM pedigree_node child_node
33
41
WHERE child_node .germplasm_id = " germplasmDbId" )
34
- )
42
+ ),
43
+ ' []' ::json
35
44
),
36
45
' pedigree' , node .pedigree_string ,
37
- ' siblings' , json_agg (
46
+ ' siblings' , COALESCE (
38
47
(
39
48
SELECT
40
- json_build_object(
41
- ' germplasmDbId' , sibling .id ,
42
- ' germplasmName' , sibling .germplasm_name
43
- )
49
+ json_agg(
50
+ json_build_object(
51
+ ' germplasmDbId' , sibling .id ,
52
+ ' germplasmName' , sibling .germplasm_name
53
+ )
54
+ )
44
55
FROM
45
- pedigree_node sibling_node
46
- JOIN
47
- pedigree_edge pe ON sibling_node .id = pe .this_node_id AND pe .edge_type = edge_type_to_int(' parent' )
48
- JOIN
49
- germplasm sibling ON sibling_node .germplasm_id = sibling .id
56
+ pedigree_node sibling_node
57
+ JOIN
58
+ pedigree_edge pe ON sibling_node .id = pe .this_node_id AND pe .edge_type = edge_type_to_int(' parent' )
59
+ JOIN
60
+ germplasm sibling ON sibling_node .germplasm_id = sibling .id
50
61
WHERE
51
- pe .connceted_node_id IN
52
- (
53
- SELECT parent_node .id
54
- FROM
55
- pedigree_node parent_node
56
- JOIN
57
- pedigree_edge e ON parent_node .id = e .connceted_node_id AND e .edge_type = edge_type_to_int(' parent' )
58
- WHERE e .this_node_id = (SELECT id FROM pedigree_node WHERE germplasm_id = " germplasmDbId" )
59
- )
60
- )
62
+ pe .connceted_node_id IN
63
+ (
64
+ SELECT parent_node .id
65
+ FROM
66
+ pedigree_node parent_node
67
+ JOIN
68
+ pedigree_edge e ON parent_node .id = e .connceted_node_id AND e .edge_type = edge_type_to_int(' parent' )
69
+ WHERE e .this_node_id = pedigree_node_id
70
+ )
71
+ ),
72
+ ' []' ::json
61
73
)
62
74
)
63
75
FROM
0 commit comments