By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
9 rows affected
11 rows affected
| id | name | sources |
|---|---|---|
| 1 | c1 | {2,3,4} |
| 2 | c2 | {5} |
| 3 | c3 | {5,6,7} |
| 4 | c4 | {7} |
| 5 | c5 | {8} |
| 6 | c6 | {9} |
| 7 | c7 | {9} |
| 8 | c8 | null |
| 9 | c9 | null |
| format |
|---|
| SELECT * FROM class c LEFT JOIN crosstab( 'SELECT target_id, source_id, 1 FROM inheritance ORDER BY 1,2' , 'VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9)' ) AS ct (id int, "1" int, "2" int, "3" int, "4" int, "5" int, "6" int, "7" int, "8" int, "9" int) USING (id) ORDER BY id; |
| id | name | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | c1 | null | 1 | 1 | 1 | null | null | null | null | null |
| 2 | c2 | null | null | null | null | 1 | null | null | null | null |
| 3 | c3 | null | null | null | null | 1 | 1 | 1 | null | null |
| 4 | c4 | null | null | null | null | null | null | 1 | null | null |
| 5 | c5 | null | null | null | null | null | null | null | 1 | null |
| 6 | c6 | null | null | null | null | null | null | null | null | 1 |
| 7 | c7 | null | null | null | null | null | null | null | null | 1 |
| 8 | c8 | null | null | null | null | null | null | null | null | null |
| 9 | c9 | null | null | null | null | null | null | null | null | null |