© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•15mo ago•
6 replies
lewisedc

What's the recommended way to handle joins that aggregate results?

drizzle orm
I'm currently converting a codebase that uses raw sql postgres queries over to drizzle, and have this query:
SELECT
  games.name,
  games.image_url,
  JSON_AGG(
    JSON_BUILD_OBJECT(
      'name', game_features.name,
      'icon_url', game_features.icon_url
    )
  ) AS features
FROM
  games
  LEFT JOIN game_features ON games.id = game_features.game_id
GROUP BY
  games.name,
  games.image_url,
  games.sort_order
ORDER BY
  games.sort_order;
SELECT
  games.name,
  games.image_url,
  JSON_AGG(
    JSON_BUILD_OBJECT(
      'name', game_features.name,
      'icon_url', game_features.icon_url
    )
  ) AS features
FROM
  games
  LEFT JOIN game_features ON games.id = game_features.game_id
GROUP BY
  games.name,
  games.image_url,
  games.sort_order
ORDER BY
  games.sort_order;

I was wondering what the recommended way of queries that aggregate joins using functions such as
JSON_AGG
JSON_AGG
or
ARRAY_AGG
ARRAY_AGG
?
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

What's is the recommended way to do DB migrations, when deploying to vercel?
Drizzle TeamDTDrizzle Team / help
11mo ago
What is the best way to handle Query Errors?
Drizzle TeamDTDrizzle Team / help
9mo ago
Joins with results in arrays
Drizzle TeamDTDrizzle Team / help
2y ago
What's the recommended way to do a basic filter by a boolean column's value?
Drizzle TeamDTDrizzle Team / help
2y ago