Database Reference
In-Depth Information
AS $$
for i in xrange(0,up_to,2):
yield i, i+1
$$ LANGUAGE plpythonu;
The important part here is that you can use any of the preceding ways to define a
PL/Python set returning function, and they all work the same. Also, you are free to
return a mixture of different types for each row of the set:
CREATE FUNCTION birthdates(OUT name text, OUT
birthdate date)
RETURNS SETOF RECORD
AS $$
return (
{'name': 'bob', 'birthdate':
'1980-10-10'},
{'name': 'mary', 'birthdate':
'1983-02-17'},
['jill', '2010-01-15'],
)
$$ LANGUAGE plpythonu;
This yields result as follows:
hannu=# select * from birthdates();
name | birthdate
------+------------
bob | 1980-10-10
mary | 1983-02-17
jill | 2010-01-15
(3 rows)
As you see, the data returning a part of PL/Pythonu is much more flexible than re-
turning data from a function written in PL/pgSQL.
Search WWH ::




Custom Search