Skip to content
Advertisement

Postgres, split single row into multiple rows

I’ve got a table with columns like:

I want to return:

I ended out writing a large query using 3 unions like this, but this does not seem right:

Is there a way to do this without the mess? Seems like I’m missing something really obvious.

Advertisement

Answer

In Postgres, you can efficiently unpivot the columns to rows with a lateral join:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement