I have a table structured like:
CREATE TABLE artists (artist TEXT UNIQUE, facts JSONB);
INSERT INTO artists (artist, facts)
VALUES ('adele', '[{"type": "full_name", "value": "Adele Laurie"}, {"type": "age", "value": "25"}]');
INSERT INTO artists (artist, facts)
VALUES ('taylor', '[{"type": "age", "value": "25"}, {"type": "last_album", "value": "1989"}]');
There are a fixed number of fact "type"s, but not every artist will have each fact. How can I select a result with columns for each fact type and null's for missing fact names?
Desired output:
| artist | full_name | age | last_album |
|--------|---------------|------|------------|
| adele | Adele Laurie | 25 | null |
| taylor | null | 25 | 1989 |