]> git.8kb.co.uk Git - postgresql/pg_2d_arrays/blob - README.md
Initial commit
[postgresql/pg_2d_arrays] / README.md
1 2d_arrays
2 ==========
3
4 Just a couple of functions and an aggregate for working with multidimensional (2 dimensional) arrays in PostgreSQL.
5
6 Usage
7 -----
8
9 ```sql
10 TEST=# select unnest_element(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]],3);
11  unnest_element
12 ----------------
13               3
14               6
15 (2 rows)
16
17 TEST=# select unnest_first(ARRAY[ARRAY[1,2,3],ARRAY[4,5,6]]);
18  unnest_dimension
19 ------------------
20  {1,2,3}
21  {4,5,6}
22 (2 rows)
23
24 -- (Ref http://stackoverflow.com/questions/9832973/initial-array-in-function-to-aggregate-multi-dimensional-array)
25 TEST=# SELECT array_agg_mult(ARRAY[ARRAY[a,b]]) 
26        FROM (SELECT 1 AS a, 2 AS b UNION SELECT 2 AS a, 4 AS b) t;
27  array_agg_mult
28 ----------------
29  {{1,2},{2,4}}
30 (1 row) 
31 ```