python - How to return resultset with Plpython3 in Postgres -
how can plpython function return result set normal sql query resultset (not text).
here function definition -
drop function if exists demo_report(); create or replace function demo_report() returns setof <what-type> $$ rv = plpy.execute("select * test") return rv $$ language plpython3u;
when execute select demo_report(); should return resultset client rather text.right getting text -
i using postgres 9.2 plpython3u on windows.
i found way desired result - table :
create table public.test ( id serial not null, name varchar(200) not null check (name <> ''), salary int, created date, constraint id primary key (id), ) ( oids = false, autovacuum_enabled = true );
my plpython3u function -
create or replace function demo_report() returns setof test $$ resp = [] rv = plpy.execute("select * test") in rv: resp.append(i) return resp $$ language 'plpython3u' volatile;
and query -
select * demo_report();
now getting desired response -
its been quite nice journey plpython till now. enjoying it.
Comments
Post a Comment