4 use SQL::Abstract::Test import => [ qw(is_same_sql_bind) ];
5 use SQL::Abstract::ExtraClauses;
7 my $sqlac = SQL::Abstract::ExtraClauses->new;
9 my ($sql, @bind) = $sqlac->select({
10 select => [ qw(artist.id artist.name), { -func => [ json_agg => 'cd' ] } ],
12 { artists => { -as => 'artist' } },
13 -join => [ cds => as => 'cd' => on => { 'cd.artist_id' => 'artist.id' } ],
15 where => { 'artist.genres', => { '@>', { -value => [ 'Rock' ] } } },
16 order_by => 'artist.name',
17 group_by => 'artist.id',
18 having => { '>' => [ { -func => [ count => 'cd.id' ] }, 3 ] }
24 SELECT artist.id, artist.name, JSON_AGG(cd)
25 FROM artists AS artist JOIN cds AS cd ON cd.artist_id = artist.id
26 WHERE artist.genres @> ?
29 HAVING COUNT(cd.id) > ?