sql >> Base de Datos >  >> RDS >> PostgreSQL

desreferenciando la matriz 2d de postgres

Considere el elenco completo de este western antes de descartarlo:

WITH tbl(arr) AS (SELECT (ARRAY[[10,11],[20,21]]))
SELECT arr[2][1]    AS the_good
      ,arr[1]       AS the_bad
      ,arr[1:1]     AS the_ugly   -- first slice of 2D-array
      ,arr[1][1:2]  AS the_ugly_twin -- 2D-array with elements 1 & 2 of 1st slice
      ,ARRAY((SELECT unnest(arr[1:1]))) AS the_righteous -- 1D-array of 1st slice
FROM   tbl;

->sqlfiddle con más ejemplos.

Algunos antecedentes en el manual aquí y aquí .