如何在Postgres中用Plpython3返回resultset

2024-05-23 22:31:21 发布

您现在位置:Python中文网/ 问答频道 /正文

plpython函数如何将结果集返回为普通sql查询结果集(而不是文本)。在

这里是函数定义-

DROP FUNCTION IF EXISTS demo_report();
CREATE OR REPLACE FUNCTION demo_report()
    RETURNS SETOF <what-type>
AS $$
    rv = plpy.execute("SELECT * FROM test")
    return rv
$$ LANGUAGE plpython3u;

当我执行选择demo_report();它应该将结果集返回给客户端,而不是文本。对吗现在我得到的是文本- enter image description here

我在Windows上使用postgres9.2和plpython3u。在


Tags: or函数文本reportsqlif定义demo
1条回答
网友
1楼 · 发布于 2024-05-23 22:31:21

我找到了获得理想结果的方法- 对于表格:

CREATE TABLE public.test
(
   id serial NOT NULL,
   name   varchar(200) NOT NULL CHECK (name <> ''),
   salary int,
   created  date,
   CONSTRAINT id PRIMARY KEY (id),
) 
WITH (
  OIDS = FALSE,
  autovacuum_enabled = true
);

我的功能是

^{pr2}$

我质疑它就像-

select * from demo_report();

现在我得到了想要的答复- enter image description here

到目前为止,与plpython的旅程非常愉快。很享受。在

相关问题 更多 >