Suppose I have the following 2d array
SELECT
ARRAY[
[100,null,null,null,null,null,null,null],
[-87.40,100,null,null,null,null,null,null],
[-2.37,15.21,100,null,null,null,null,null],
[-68.01,67.04,36.26,100,null,null,null,null],
[-2.19,-3.59,-35.09,-22.58,100,null,null,null],
[0.46,-18.19,-57.98,-34.93,45.22,100,null,null],
[-75.67,51.66,31.01,75.60,15.85,5.37,100,null],
[49.44,-68.09,-46.72,-58.14,67.34,68.20,-16.88,100]
]::TEXT[][] AS matrix
Assume this is stored in a database table. How would I go about querying this so as to give me a row back per array element, as in 8 rows, each of which is a text array. If I use UNNEST like the following
SELECT UNNEST(t1.matrix) FROM (
SELECT
ARRAY[
[100,null,null,null,null,null,null,null],
[-87.40,100,null,null,null,null,null,null],
[-2.37,15.21,100,null,null,null,null,null],
[-68.01,67.04,36.26,100,null,null,null,null],
[-2.19,-3.59,-35.09,-22.58,100,null,null,null],
[0.46,-18.19,-57.98,-34.93,45.22,100,null,null],
[-75.67,51.66,31.01,75.60,15.85,5.37,100,null],
[49.44,-68.09,-46.72,-58.14,67.34,68.20,-16.88,100]
]::TEXT[][] AS matrix
) t1;
It returns a row for each element of each sub array. The output I'm looking for would be a text array column with 8 rows, e.g,
--Desired Result
[100,null,null,null,null,null,null,null]
[-87.40,100,null,null,null,null,null,null]
[-2.37,15.21,100,null,null,null,null,null]
[-68.01,67.04,36.26,100,null,null,null,null]
[-2.19,-3.59,-35.09,-22.58,100,null,null,null]
[0.46,-18.19,-57.98,-34.93,45.22,100,null,null]
[-75.67,51.66,31.01,75.60,15.85,5.37,100,null]
[49.44,-68.09,-46.72,-58.14,67.34,68.20,-16.88,100]
As opposed to
"100"
.
.
.
.
.
.
.
"-87.40"
"100"
.
Any pointers in the right direction would be appreciated. I'm using v11.9. Thanks