Created
September 30, 2012 08:44
-
-
Save ianmcorvidae/3806278 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH groups AS ( | |
| SELECT DISTINCT ON (artist.id) artist.id, artist.name FROM | |
| artist | |
| JOIN l_artist_artist laa ON laa.entity1 = artist.id | |
| JOIN link on link.id = laa.link | |
| JOIN link_type on link_type.id = link.link_type | |
| WHERE artist.type IS DISTINCT FROM 1 | |
| AND link_type.name IN ('member of band', 'collaboration', 'conductor position') | |
| AND link_type.entity_type0 = 'artist' | |
| AND link_type.entity_type1 = 'artist'), | |
| persons_entity0 AS ( | |
| SELECT DISTINCT ON (artist.id) artist.id, artist.name FROM | |
| artist | |
| JOIN l_artist_artist laa ON laa.entity0 = artist.id | |
| JOIN link on link.id = laa.link | |
| JOIN link_type on link_type.id = link.link_type | |
| WHERE artist.type IS DISTINCT FROM 1 | |
| AND link_type.name IN ('member of band', 'collaboration', 'voice actor', 'conductor position', 'is person', 'married', 'sibling', 'parent', 'involved with') | |
| AND link_type.entity_type0 = 'artist' | |
| AND link_type.entity_type1 = 'artist'), | |
| persons_entity1 AS ( | |
| SELECT DISTINCT ON (artist.id) artist.id, artist.name FROM | |
| artist | |
| JOIN l_artist_artist laa ON laa.entity1 = artist.id | |
| JOIN link on link.id = laa.link | |
| JOIN link_type on link_type.id = link.link_type | |
| WHERE artist.type IS DISTINCT FROM 1 | |
| AND link_type.name IN ('catalogued', 'is person', 'married', 'sibling', 'parent', 'involved with') | |
| AND link_type.entity_type0 = 'artist' | |
| AND link_type.entity_type1 = 'artist'), | |
| artists AS ( | |
| SELECT DISTINCT ON (id) id, name FROM | |
| (SELECT * FROM persons_entity0 | |
| UNION | |
| SELECT * from persons_entity1) AS persons | |
| EXCEPT | |
| SELECT * from groups) | |
| SELECT DISTINCT ON (artists.id) artists.id AS artist_id, row_number() OVER (ORDER BY musicbrainz_collate(name.name), artists.id) | |
| FROM artists | |
| JOIN artist_name AS name ON artists.name = name.id | |
| LIMIT 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment