NOTICE: table "tbl16369_test" does not exist, skipping
create table tbl16369_test(col text);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'col' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into tbl16369_test values ('789'),('789'),('789'),('789'),('789'),('789');
create table tbl16369_test1(a text, b int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into tbl16369_test1 values ('456',456),('012',12),('901',901),('678',678),('789',789),('345',345);
insert into tbl16369_test1 values ('456',456),('012',12),('901',901),('678',678),('789',789),('345',345);
create table tbl16369_x(x int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into tbl16369_x values (456),(12),(901),(678),(789),(345);
insert into tbl16369_x values (456),(12),(901),(678),(789),(345);
INSERT INTO tbl16369_zipcode_gis VALUES ( 94403, 123, 123 );
INSERT INTO tbl16369_zipcode_gis VALUES ( 94404, 321, 321 );
INSERT INTO tbl16369_zipcode_gis VALUES ( 90405, 234, 234 );
CREATE FUNCTION tbl16369_func1() RETURNS tbl16369_test AS $$
DECLARE
res tbl16369_test;
BEGIN
select * into res from tbl16369_test;
return res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func2() RETURNS tbl16369_test AS $$
DECLARE
rec tbl16369_test;
ref refcursor;
BEGIN
OPEN ref FOR SELECT * FROM tbl16369_test;
FETCH ref into rec;
CLOSE ref;
RETURN rec;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func3(refcursor, refcursor) RETURNS SETOF refcursor AS $$
BEGIN
OPEN $1 FOR SELECT * FROM tbl16369_zipcode_gis;
RETURN NEXT $1;
OPEN $2 FOR SELECT * FROM tbl16369_test;
RETURN NEXT $2;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func4() RETURNS tbl16369_test AS $$
DECLARE
res tbl16369_test;
BEGIN
select tbl16369_func1() into res;
return res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func5() RETURNS tbl16369_test AS $$
DECLARE
res tbl16369_test;
BEGIN
select tbl16369_func2() into res;
return res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func6() RETURNS setof refcursor AS $$
DECLARE
ref1 refcursor;
BEGIN
select tbl16369_func3('a','b') into ref1;
return next ref1;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func7() RETURNS tbl16369_test AS $$
DECLARE
ref refcursor;
rec tbl16369_test;
BEGIN
OPEN ref FOR SELECT tbl16369_func1();
FETCH ref into rec;
CLOSE ref;
RETURN rec;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func8() RETURNS tbl16369_test AS $$
DECLARE
ref refcursor;
rec tbl16369_test;
BEGIN
OPEN ref FOR SELECT tbl16369_func2();
FETCH ref into rec;
CLOSE ref;
RETURN rec;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func9() RETURNS setof refcursor AS $$
DECLARE
ref refcursor;
ref1 refcursor;
BEGIN
OPEN ref FOR SELECT tbl16369_func3('a','b');
FETCH ref into ref1;
CLOSE ref;
RETURN next ref1;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE OR REPLACE FUNCTION tbl16369_func10(param_numcount integer)
RETURNS tbl16369_test AS $$
DECLARE res tbl16369_test;
BEGIN
IF param_numcount < 0 THEN
RAISE EXCEPTION 'Negative numbers are not allowed';
ELSIF param_numcount > 0 THEN
RAISE NOTICE 'Yo there I''m number %, next: %', param_numcount, param_numcount -1;
res:= tbl16369_func10(param_numcount - 1);
ELSE
RAISE INFO 'Alas we are at the end of our journey';
select * into res from tbl16369_test;
END IF;
RETURN res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE OR REPLACE FUNCTION tbl16369_func11(param_numcount integer) RETURNS tbl16369_test AS $$
DECLARE res tbl16369_test; ref refcursor;
BEGIN
IF param_numcount < 0 THEN
RAISE EXCEPTION 'Negative numbers are not allowed';
ELSIF param_numcount > 0 THEN
RAISE NOTICE 'Yo there I''m number %, next: %', param_numcount, param_numcount -1;
res := tbl16369_func11(param_numcount - 1);
ELSE
RAISE INFO 'Alas we are at the end of our journey';
open ref for select * from tbl16369_test;
FETCH ref into res;
CLOSE ref;
END IF;
RETURN res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
CREATE FUNCTION tbl16369_func12() RETURNS float AS $$
DECLARE
ref refcursor;
res float;
BEGIN
OPEN ref FOR select avg(foo.b) from (select tbl16369_test1.b from tbl16369_test,tbl16369_test1 where tbl16369_test.col=tbl16369_test1.a and tbl16369_test1.b in (select x from tbl16369_x)) as foo;
FETCH ref into res;
CLOSE ref;
RETURN res;
END;
$$ LANGUAGE plpgsql READS SQL DATA;
Drop table if exists zipcode_gis;
NOTICE: table "zipcode_gis" does not exist, skipping
Drop table if exists x;
NOTICE: table "x" does not exist, skipping
Drop table if exists test1;
NOTICE: table "test1" does not exist, skipping
Drop function complexquery();
ERROR: function complexquery() does not exist
Drop table if exists test;
NOTICE: table "test" does not exist, skipping
create table test(col text);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'col' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into test values ('456'),('789'),('012'),('345'),('678'),('901');
create table test1(a text, b int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into test1 values ('456',456),('012',12),('901',901),('678',678),('789',789),('345',345);
insert into test1 values ('654',456),('210',12),('109',901),('876',678),('987',789),('543',345);
create table x(x int);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'x' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into x values (456),(12),(901),(678),(789),(345);
insert into x values (456),(12),(901),(678),(789),(345);
select avg(foo.b) from (select test1.b from test,test1 where test.col=test1.a and test1.b in (select x from x)) as foo;
avg
------------------
530.166666666667
(1 row)
CREATE FUNCTION complexquery() RETURNS float AS $$
DECLARE
ref refcursor;
res float;
BEGIN
OPEN ref FOR select avg(foo.b) from (select test1.b from test,test1 where test.col=test1.a and test1.b in (select x from x)) as foo;