aboutsummaryrefslogtreecommitdiff
path: root/src/pl/plpython/sql/plpython_setof.sql
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2009-08-12 16:37:26 +0000
committerPeter Eisentraut <peter_e@gmx.net>2009-08-12 16:37:26 +0000
commit9d9848668fd868a4e51f3a3f22c2807ff0e46582 (patch)
tree22b0152fb889ca42d3e4c6ce888d2024b8b8c98b /src/pl/plpython/sql/plpython_setof.sql
parentef7574eb014b66d99a5e68cc254e7a2282e69a00 (diff)
downloadpostgresql-9d9848668fd868a4e51f3a3f22c2807ff0e46582.tar.gz
postgresql-9d9848668fd868a4e51f3a3f22c2807ff0e46582.zip
Split the plpython regression test into test cases arranged by topic, instead
of the previous monolithic setup-create-run sequence, that was apparently inherited from a previous test infrastructure, but makes working with the tests and adding new ones weird.
Diffstat (limited to 'src/pl/plpython/sql/plpython_setof.sql')
-rw-r--r--src/pl/plpython/sql/plpython_setof.sql46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/pl/plpython/sql/plpython_setof.sql b/src/pl/plpython/sql/plpython_setof.sql
new file mode 100644
index 00000000000..881d90222fe
--- /dev/null
+++ b/src/pl/plpython/sql/plpython_setof.sql
@@ -0,0 +1,46 @@
+--
+-- Test returning SETOF
+--
+
+CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$
+return [ content ]*count
+$$ LANGUAGE plpythonu;
+
+CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$
+t = ()
+for i in xrange(count):
+ t += ( content, )
+return t
+$$ LANGUAGE plpythonu;
+
+CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$
+class producer:
+ def __init__ (self, icount, icontent):
+ self.icontent = icontent
+ self.icount = icount
+ def __iter__ (self):
+ return self
+ def next (self):
+ if self.icount == 0:
+ raise StopIteration
+ self.icount -= 1
+ return self.icontent
+return producer(count, content)
+$$ LANGUAGE plpythonu;
+
+
+-- Test set returning functions
+SELECT test_setof_as_list(0, 'list');
+SELECT test_setof_as_list(1, 'list');
+SELECT test_setof_as_list(2, 'list');
+SELECT test_setof_as_list(2, null);
+
+SELECT test_setof_as_tuple(0, 'tuple');
+SELECT test_setof_as_tuple(1, 'tuple');
+SELECT test_setof_as_tuple(2, 'tuple');
+SELECT test_setof_as_tuple(2, null);
+
+SELECT test_setof_as_iterator(0, 'list');
+SELECT test_setof_as_iterator(1, 'list');
+SELECT test_setof_as_iterator(2, 'list');
+SELECT test_setof_as_iterator(2, null);