使用pandas.read_sql_查询with PostgreSQL返回空的DataFram

2024-10-01 05:04:31 发布

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

代码如下:

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(又添加了两个内部联接)时,如下所示:

^{pr2}$

我有一个空的数据帧。然后我在屏幕上打印SQL,复制并粘贴到DataGrip上,SQL起作用了,它可以返回行,但在程序中,使用read_sql_query()返回空,我不知道为什么。在


Tags: to数据代码idreadsqldatecode