It's funky at first but hopefully you learn to love it. You'll be a better engineer with data that pops out in the right shape/scope the first time, too.
I'll add a few comments to the earlier snippet in case that helps.
Happy to answer any other questions that you come up with!
Edit: Fixed up a few Redshift-specific functions to be Postgres friendly in the example.