python - 将 pandas.read_sql_query 与 PostgreSQL 一起使用会返回 Empty DataFrame
问题描述
这是代码:
sql = "select to_char(f_date at time zone 'GMT-8', 'YYYY-MM-DD
HH24:MI:SS') as f_date, f_open, f_close, f_high, f_low, f_volume
from choice_kwindminutefinancehistory
INNER JOIN choice_financecode
ON choice_kwindminutefinancehistory.f_code_id=choice_financecode.id
where choice_financecode.f_code = '" + stock + "'
AND f_date >='" + start_date + "' and f_date<='" + end_date + "'"
df = pd.read_sql_query(sql, con=self.engine)
这工作得很好,我从查询中得到了一个数据框,但是当我更改 SQL(添加了两个内部连接)时,如下所示:
sql = "select to_char(kwm.f_date at time zone 'GMT-8', 'YYYY-MM-DD
HH24:MI:SS') as f_date , kwm.f_open as f_open, kwm.f_close as f_close,
kwm.f_high as f_high, kwm.f_low as f_low, kwm.f_volume as f_volume,
dfh.f_date as pre_date, dfh.f_open as pre_open, dfh.f_close as pre_close,
dfh.f_high as pre_high, dfh.f_low as pre_low, dfh2.f_volume as today_volumn
from choice_kwindminutefinancehistory as kwm
INNER JOIN choice_financecode as fc ON kwm.f_code_id=fc.id
INNER JOIN choice_dailyfinancehistory as dfh ON kwm.f_code_id = dfh.f_code_id
and dfh.f_date = '" + pre_date + "'
INNER JOIN choice_dailyfinancehistory as dfh2 ON kwm.f_code_id = dfh2.f_code_id
and dfh2.f_date = '" + start_date + "'
where fc.f_code = '" + stock + "' AND kwm.f_date >= '" + start_date + "'
and kwm.f_date<='" + end_date + "'"
我有一个空数据框。然后我在屏幕上打印SQL,复制并粘贴到DataGrip,SQL 工作,它可以返回行,但是在程序中,使用read_sql_query()
它返回空,我不知道为什么。
解决方案
推荐阅读
- powershell - 如何在启用继承的情况下 PS Move-Item?
- powershell - 替换所有txt文件中的一个字符
- python - 用 Python 阅读最新的 Hotmail 电子邮件
- python - 如何使用来自相关 DataFrame 的位置值形成“JSON”?
- mysql - 查找每天在每个国家/地区下单的用户数量
- javascript - 在javascript中添加基于日期的数组对象?
- javascript - javascript中嵌套函数的try/catch问题
- boolean-expression - 通过替换括号重新排列布尔表达式
- flutter - 当我的 Draggable 小部件移动时,如何使我的拖动目标跟随?
- .net-core - Azure DevOps 将工件打包应用程序部署到 IIS