问题描述
我有一个大查询,我需要在Django中在postgres DB上手动运行。当我在psql中手动运行查询时,我没有问题,但是当我在Python中使用cursor.execute()
运行查询时,出现错误。
select id from mytable,jsonb_array_elements(details) as detail_elements;
如您所见,第二部分从jsonb字段中获取了一些信息,在较大的查询中,我将使用更多信息。这个简单的查询在psql中运行得很好(仅显示id列表),因此我在Django中尝试了此方法:
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("select id from mytable,jsonb_array_elements(details) as detail_elements;")
rows = cursor.fetchall()
但我收到此错误:
psycopg2.errors.InvalidParameterValue: cannot extract elements from a scalar
有人知道Django试图做什么,这与直接在psql中运行它有所不同吗?欢迎所有提示!
我正在Ubuntu 20.04上运行Postgres 12.2和Django 3.0.9
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)