I have some data from a query and the shape pretty much looks like this:
| Id | category | value |
|----|----------|-------|
| 1 | 'a' | 2 |
| 1 | 'b' | 5 |
| 2 | 'a' | 3 |
| 2 | 'b' | 4 |
I'm wanting to group that data and insert it into a table of the following structure
| Id | category_a_value | category_b_value|
|----|------------------|-----------------|
| 1 | 2 | 5 |
| 2 | 3 | 4 |
Is there a nice way to achieve this in Postgres? I couldn't figure out to group the data how I wanted so eventually I tried a INSERT INTO and on conflict approach selecting from the orginial query but this failed because you can't affect a row multiple times.
Thanks in advance