+CREATE VIEW bug_status --(id,bug_num,tags,subject,
+-- severity,package,originator,log_modified,date,
+-- last_modified, blocks, blockedby, mergedwith,
+-- fixed_versions,found_versions)
+ AS
+ SELECT b.id AS id,
+ b.id AS bug_num,
+ string_agg(t.tag,',') AS tags,
+ b.subject AS subject,
+ (SELECT s.severity FROM severity s WHERE s.id=b.severity) AS severity,
+ (SELECT string_agg(package.package,',' ORDER BY package)
+ FROM (SELECT bp.pkg AS package
+ FROM bug_binpackage bbp
+ JOIN bin_pkg bp ON bbp.bin_pkg=bp.id
+ WHERE bbp.bug=b.id
+ UNION
+ SELECT CONCAT('src:',sp.pkg) AS package
+ FROM bug_srcpackage bsp
+ JOIN src_pkg sp ON bsp.src_pkg=sp.id
+ WHERE bsp.bug=b.id) AS package
+ ) AS package,
+ b.submitter_full AS originator,
+ EXTRACT(EPOCH FROM b.log_modified) AS log_modified,
+ EXTRACT(EPOCH FROM b.creation) AS date,
+ EXTRACT(EPOCH FROM b.last_modified) AS last_modified,
+ b.done_full AS done,
+ string_agg(bb.blocks::text,' ' ORDER BY bb.blocks) AS blocks,
+ string_agg(bbb.bug::text,' ' ORDER BY bbb.bug) AS blockedby,
+ (SELECT string_agg(bug.bug::text,' ' ORDER BY bug.bug)
+ FROM (SELECT bm.merged AS bug FROM bug_merged bm WHERE bm.bug=b.id
+ UNION
+ SELECT bm.bug AS bug FROM bug_merged bm WHERE bm.merged=b.id) AS bug) AS mergedwith,
+ (SELECT string_agg(bv.ver_string,' ') FROM bug_ver bv WHERE bv.bug=b.id AND bv.found IS TRUE)
+ AS found_versions,
+ (SELECT string_agg(bv.ver_string,' ') FROM bug_ver bv WHERE bv.bug=b.id AND bv.found IS FALSE)
+ AS fixed_versions
+ FROM bug b
+ LEFT JOIN bug_tag bt ON bt.bug=b.id
+ LEFT JOIN tag t ON bt.tag=t.id
+ LEFT JOIN bug_blocks bb ON bb.bug=b.id
+ LEFT JOIN bug_blocks bbb ON bbb.blocks=b.id
+ GROUP BY b.id;