To do something similar without custom extensions, it's worth knowing about Postgres's lateral joins, which allow you to reuse columns from the left side of your join in the right side. It basically realizes the "enrich my results" promise that SQL should always have had, and makes incredibly flexible analytics queries possible without ever needing to indent more than once!
https://heap.io/blog/postgresqls-powerful-new-join-type-late...
https://ddrscott.github.io/blog/2017/what-the-sql-lateral/