Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Flask、SQLAlchemy或psycopg2从Postgres中的游标获取数据_Python_Postgresql_Sqlalchemy_Psycopg2 - Fatal编程技术网

Python 如何使用Flask、SQLAlchemy或psycopg2从Postgres中的游标获取数据

Python 如何使用Flask、SQLAlchemy或psycopg2从Postgres中的游标获取数据,python,postgresql,sqlalchemy,psycopg2,Python,Postgresql,Sqlalchemy,Psycopg2,我正在使用Flask并在Postgres数据库上制作程序,如 CREATE OR REPLACE FUNCTION "public"." "() RETURNS "pg_catalog"."refcursor" AS $BODY$ DECLARE ref refcursor; BEGIN OPEN ref FOR select posts.*, users.username, users.name from posts left join users on posts.u

我正在使用Flask并在Postgres数据库上制作程序,如

CREATE OR REPLACE FUNCTION "public"."   "()
  RETURNS "pg_catalog"."refcursor" AS $BODY$
DECLARE
    ref refcursor;
BEGIN
    OPEN ref FOR select posts.*, users.username, users.name from posts left join users on posts.user_id = users.id;
    RETURN ref;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
在我的代码中使用SQLAlchemy

connection.execute("SELECT home_data()").fetchall()
它将光标名称home_数据返回为“未命名门户1”

使用psycopg2

conn = psycopg2.connect(host="localhost",database="xxxx", user="xxxx", password="xxxx")

def home_pro():
        cur = conn.cursor()
        return cur.callproc('home_data')
这段代码不返回任何值

请帮助我如何从我的程序中获取数据,我在互联网上搜索了这个,但什么都没有得到。

我得到了答案

   res = cur.callproc('getPerson')
   row = cur.fetchone()

   cur.execute(f'FETCH ALL IN "{row[0]}"')
   results = cur.fetchall()

太神了谢谢你@vipin