Following up from my previous question:
Pixel values of raster records to be inserted in the table as columns
Imagine my query result has 5300 row as results like:
+-------+
|value |
+-------+
| 15624 |
| 15899 |
| 56267 |
| 85955 |
+-------+
I want them to be in a table and first 53 rows in val1 column, second 53 rows in val2 column and so on. In the end I will have 100 new columns in my table. Is this possible? and if so, how can I achieve it?
Here’s a possibly somewhat saner approach using multi-dimensional arrays.
Please never, ever, ever, ever use the following query:
The correct way to solve this problem is almost certainly in your application. SQL is good at many things. This isn’t one of them, especially in PostgreSQL with its very limited pivot support. In any database this would be a crazy thing to do.
As far as I’m concerned, if I have to use a query just to generate the column-list, that’s a sign the system is being forced to do something it isn’t well suited for: