I have a table with data
id | location | data |
-----------------------
0 | point 0,1 | "Dachshund"
1 | point 0,0 | "Dog Breeds"
2 | point 1,0 | "Quantity"
3 | point 0,1 | "Rhodesian"
4 | point 1,1 | "2"
5 | point 1,2 | "1"
Am looking to translate it into:
0 as text | 1 as text
--------------------------
"Dog Breeds" | "Quantity"
"Dachshund" | "2"
"Rhodesian" | "1"
Is there a way to dynamically do this in PostgresSQL? The data points could expand an arbitrary amount of cells and columns in any direction. The resulting column names should always be of type text and can just be named by the y coordinate of the location given in the first table.
I have tried to accomplish this with Postgres tablefunc
and crosstab
however that function appears to require the columns to be predefined.