1

我正在plpythongreenplum中创建一个函数。forplpy.prepare("INSERT INTO ....")失败并出现错误:
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)
plpython 函数中不允许插入吗?我没有看到文档中的插入有太多帮助。 greenplum plpython 文档

4

2 回答 2

1

您可以使用plpy.execute("INSERT INTO ....")而不是plpy.prepare("INSERT INTO ....").

plpy.prepare()用于准备好的语句。如果您想使用它,请参考以下示例。

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=# 

以下是可用pypl功能(此处为Greenplum 5.10 文档

于 2018-08-18T14:23:05.707 回答
0

我不确定插入是否可以在这里工作;将插入语句放入 gp 函数并从 plpython func 中触发“select my_func(arg1, arg2)”

于 2018-06-30T04:52:04.223 回答