Skip to content

Instantly share code, notes, and snippets.

PREPARE prep_1 AS SELECT json_agg(r.*) FROM (
SELECT
album.title as title,
json_agg(track.*) as tracks
FROM
album
LEFT OUTER JOIN
track
ON
(album.id = track.album_id)
{
album (where: {year: {_eq: 2018}}) {
title
tracks {
id
title
}
}
}
SELECT json_agg(r.*) FROM (
SELECT
album.title as title,
json_agg(track.*) as tracks
FROM
album
LEFT OUTER JOIN
track
ON
(album.id = track.album_id)
[
{
"title" : "Album1",
"tracks": [
{"id" : 1, "title": "track1"},
{"id" : 2, "title": "track2"}
]
},
{
"title" : "Album2",
SELECT
album.id as album_id,
album.title as album_title,
track.id as track_id,
track.title as track_title
FROM
album
LEFT OUTER JOIN
track
ON
select id, title from tracks where album_id IN {the list of album ids}
select id,title from album where year = 2018;
select id, title from tracks where album_id = <album-id>
select id,title from album where year = 2018;
{
album (where: {year: {_eq: 2018}}) {
title
tracks {
id
title
}
}
}