I am creating a plpython
function in greenplum.
for plpy.prepare("INSERT INTO ....")
fails with error:
ERROR: plpy.SPIError: function cannot execute on segment because it issues a non-SELECT statement (plpython.c:4656) (seg4 slice1 den-gp5-seg03:40000 pid=119213) (cdbdisp.c:1322)
Are inserts not allowed in plpython functions?
I don't see much help with inserts in documentation.
greenplum plpython doc
Asked
Active
Viewed 1,334 times
1

Deepak K M
- 521
- 1
- 5
- 13
2 Answers
1
You can use plpy.execute("INSERT INTO ....")
rather than plpy.prepare("INSERT INTO ....")
.
plpy.prepare()
is used for prepared statement. If you want to use it, please refer to the following example.
postgres=# create table your_table (yourstr char(2), yournum int);
CREATE TABLE
postgres=# do $$
postgres$# plan = plpy.prepare("insert into your_table values($1,$2)", ["text", "int"]);
postgres$# plpy.execute(plan, ["Gx", 7]);
postgres$# $$ language plpython3u;
DO
postgres=# select * from your_table;
yourstr | yournum
---------+---------
Gx | 7
(1 row)
postgres=#

C.C. Hsu
- 169
- 2
0
I'm not sure if insert will work here; put insert statement in a gp function and fire a "select my_func(arg1, arg2)" from plpython func

Gurupreet Singh Bhatia
- 708
- 6
- 17