-- Check that compensation is properly working.
CREATE OR REPLACE FUNCTION just_one() RETURNS int
LANGUAGE python AS
$python$
def main():
	return 1
$python$;
SELECT * FROM just_one() AS g(i) LIMIT 0;
 i 
---
(0 rows)

SELECT * FROM just_one() AS g(i);
 i 
---
 1
(1 row)

CREATE OR REPLACE FUNCTION one_two_three() RETURNS SETOF int
LANGUAGE python AS
$python$
def main():
	return (1,2,3)
$python$;
SELECT one_two_three();
 one_two_three 
---------------
             1
             2
             3
(3 rows)

SELECT one_two_three() LIMIT 2;
 one_two_three 
---------------
             1
             2
(2 rows)

SELECT * FROM one_two_three();
 one_two_three 
---------------
             1
             2
             3
(3 rows)

SELECT * FROM one_two_three() LIMIT 2;
 one_two_three 
---------------
             1
             2
(2 rows)

CREATE OR REPLACE FUNCTION one_two_three_records(OUT i int, OUT k text) RETURNS SETOF RECORD
LANGUAGE python AS
$python$
def main():
	return (
		(1,'one'),
		(2,'two'),
		(3,'three'),
	)
$python$;
SELECT one_two_three_records();
 one_two_three_records 
-----------------------
 (1,one)
 (2,two)
 (3,three)
(3 rows)

SELECT one_two_three_records() LIMIT 2;
 one_two_three_records 
-----------------------
 (1,one)
 (2,two)
(2 rows)

SELECT * FROM one_two_three_records();
 i |   k   
---+-------
 1 | one
 2 | two
 3 | three
(3 rows)

SELECT * FROM one_two_three_records() LIMIT 2;
 i |  k  
---+-----
 1 | one
 2 | two
(2 rows)

CREATE OR REPLACE FUNCTION one_two_three_records_d(OUT i int, OUT k text) RETURNS SETOF RECORD
LANGUAGE python AS
$python$
def main():
	return (
		dict(i = 1, k = 'one'),
		dict(i = 2, k = 'two'),
		dict(i = 3, k = 'three'),
		dict(i = 4, k = None),
	)
$python$;
SELECT one_two_three_records_d();
 one_two_three_records_d 
-------------------------
 (1,one)
 (2,two)
 (3,three)
 (4,)
(4 rows)

SELECT one_two_three_records_d() LIMIT 2;
 one_two_three_records_d 
-------------------------
 (1,one)
 (2,two)
(2 rows)

SELECT * FROM one_two_three_records_d();
 i |   k   
---+-------
 1 | one
 2 | two
 3 | three
 4 | 
(4 rows)

SELECT * FROM one_two_three_records_d() LIMIT 2;
 i |  k  
---+-----
 1 | one
 2 | two
(2 rows)

