Is there a unpivot equivalent function in PostgreSQL?
A:
You can use the crosstab()
function in PostgreSQL to implement pivot functionality.
See http://www.postgresql.org/docs/current/static/tablefunc.html
It's the reverse operation of a pivot. I'm not sure if it's straightforward to implement unpivot with crosstab()
but perhaps this can get you started.
Bill Karwin
2009-09-22 01:54:19
A:
I wrote a horrible unpivot function for PostgreSQL. It's rather slow but it at least returns results like you'd expect an unpivot operation to.
https://cgsrv1.arrc.csiro.au/blog/2010/05/14/unpivotuncrosstab-in-postgresql/
Hopefully you can find it useful..
Josh LOL
2010-05-14 07:29:03