~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/pl/plpython/sql/plpython_setof.sql

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- Test returning SETOF
 
3
--
 
4
 
 
5
CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$
 
6
return 37
 
7
$$ LANGUAGE plpythonu;
 
8
 
 
9
SELECT test_setof_error();
 
10
 
 
11
 
 
12
CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$
 
13
return [ content ]*count
 
14
$$ LANGUAGE plpythonu;
 
15
 
 
16
CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$
 
17
t = ()
 
18
for i in range(count):
 
19
        t += ( content, )
 
20
return t
 
21
$$ LANGUAGE plpythonu;
 
22
 
 
23
CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$
 
24
class producer:
 
25
        def __init__ (self, icount, icontent):
 
26
                self.icontent = icontent
 
27
                self.icount = icount
 
28
        def __iter__ (self):
 
29
                return self
 
30
        def next (self):
 
31
                if self.icount == 0:
 
32
                        raise StopIteration
 
33
                self.icount -= 1
 
34
                return self.icontent
 
35
return producer(count, content)
 
36
$$ LANGUAGE plpythonu;
 
37
 
 
38
CREATE FUNCTION test_setof_spi_in_iterator() RETURNS SETOF text AS
 
39
$$
 
40
    for s in ('Hello', 'Brave', 'New', 'World'):
 
41
        plpy.execute('select 1')
 
42
        yield s
 
43
        plpy.execute('select 2')
 
44
$$
 
45
LANGUAGE plpythonu;
 
46
 
 
47
 
 
48
-- Test set returning functions
 
49
SELECT test_setof_as_list(0, 'list');
 
50
SELECT test_setof_as_list(1, 'list');
 
51
SELECT test_setof_as_list(2, 'list');
 
52
SELECT test_setof_as_list(2, null);
 
53
 
 
54
SELECT test_setof_as_tuple(0, 'tuple');
 
55
SELECT test_setof_as_tuple(1, 'tuple');
 
56
SELECT test_setof_as_tuple(2, 'tuple');
 
57
SELECT test_setof_as_tuple(2, null);
 
58
 
 
59
SELECT test_setof_as_iterator(0, 'list');
 
60
SELECT test_setof_as_iterator(1, 'list');
 
61
SELECT test_setof_as_iterator(2, 'list');
 
62
SELECT test_setof_as_iterator(2, null);
 
63
 
 
64
SELECT test_setof_spi_in_iterator();