Skip to content

Instantly share code, notes, and snippets.

@shapr
Created January 17, 2024 23:23
Show Gist options
  • Save shapr/4b6f3b2598c68435ada6cdfb07712923 to your computer and use it in GitHub Desktop.
Save shapr/4b6f3b2598c68435ada6cdfb07712923 to your computer and use it in GitHub Desktop.
why can't this be USING ?
 \set howmany 1
 SELECT
   genre.name AS genre,
   CASE WHEN length(scrubby.name) > 15 THEN
     substring(scrubby.name FROM 1 FOR 15) || ''
   ELSE
     scrubby.name
   END AS track,
   artist.name AS artist
 FROM
   genre
   LEFT JOIN LATERAL (
     SELECT
	track.name,
	track.album_id,
	count(playlist_id)
     FROM
	track
	LEFT JOIN playlist_track USING (track_id)
     WHERE
	track.genre_id = genre.genre_id -- why can't this be *USING*?
     GROUP BY
	track.track_id
     ORDER BY
	count DESC
     LIMIT :'howmany') AS scrubby (name,
     album_id,
     count) ON TRUE
   JOIN album USING (album_id)
   JOIN artist USING (artist_id)
 ORDER BY
   genre.name,
   scrubby.count DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment