summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2008-04-28 14:48:58 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2008-04-28 14:48:58 +0000
commit1fcb977a13d70f8746ec86488fd9afc0569e7784 (patch)
treebcb05835226f8663ad20ed55c8f3fb712ab0ff5b /src/test
parenta1d479f518394a68f47e3dd64ac5c4626da6c534 (diff)
Add generate_subscripts, a series-generation function which generates an
array's subscripts. Pavel Stehule, some editorialization by me.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/arrays.out30
-rw-r--r--src/test/regress/sql/arrays.sql17
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out
index c82cd3919b9..9ab372d15a5 100644
--- a/src/test/regress/expected/arrays.out
+++ b/src/test/regress/expected/arrays.out
@@ -903,3 +903,33 @@ select c2[2].f2 from comptable;
drop type _comptype;
drop table comptable;
drop type comptype;
+create or replace function unnest1(anyarray)
+returns setof anyelement as $$
+select $1[s] from generate_subscripts($1,1) g(s);
+$$ language sql immutable;
+create or replace function unnest2(anyarray)
+returns setof anyelement as $$
+select $1[s1][s2] from generate_subscripts($1,1) g1(s1),
+ generate_subscripts($1,2) g2(s2);
+$$ language sql immutable;
+select * from unnest1(array[1,2,3]);
+ unnest1
+---------
+ 1
+ 2
+ 3
+(3 rows)
+
+select * from unnest2(array[[1,2,3],[4,5,6]]);
+ unnest2
+---------
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+(6 rows)
+
+drop function unnest1(anyarray);
+drop function unnest2(anyarray);
diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql
index 192648a39b6..6590cad36c4 100644
--- a/src/test/regress/sql/arrays.sql
+++ b/src/test/regress/sql/arrays.sql
@@ -340,3 +340,20 @@ select c2[2].f2 from comptable;
drop type _comptype;
drop table comptable;
drop type comptype;
+
+create or replace function unnest1(anyarray)
+returns setof anyelement as $$
+select $1[s] from generate_subscripts($1,1) g(s);
+$$ language sql immutable;
+
+create or replace function unnest2(anyarray)
+returns setof anyelement as $$
+select $1[s1][s2] from generate_subscripts($1,1) g1(s1),
+ generate_subscripts($1,2) g2(s2);
+$$ language sql immutable;
+
+select * from unnest1(array[1,2,3]);
+select * from unnest2(array[[1,2,3],[4,5,6]]);
+
+drop function unnest1(anyarray);
+drop function unnest2(anyarray);