简体   繁体   English

使用 ODBC 从 hfsql 数据库读取日期时出现 ValueError

[英]ValueError when reading dates from hfsql database using ODBC

With some struggles I connected to a hfsql server using ODBC.经过一番挣扎,我使用 ODBC 连接到 hfsql 服务器。 I've tried both pypyodbc and pyodbc.我已经尝试过pypyodbc和pyodbc。 My goal is to get some insights in the data (and visualize some aspects).我的目标是获得对数据的一些见解(并可视化某些方面)。

For some planning visualization I need to read out some of the data, which works fine for most tables and columns.对于一些规划可视化,我需要读出一些数据,这对大多数表格和列都适用。 However, when I try to read out a column containing dates i get a ValueError:但是,当我尝试读出包含日期的列时,我得到一个 ValueError:

    invalid literal for int() with base 10: ''

All rows contain a valid date.所有行都包含有效日期。

This is the code that currently produces the error above:这是当前产生上述错误的代码:

deadlines = db.cursor()
query = ("SELECT DeliveryDate FROM Orders WHERE Finished = 0")
deadlines.execute(query)
print(deadlines.fetchone()) #<- this goes wrong

db is the database (it works with other queries) db 是数据库(它与其他查询一起使用)

    print(deadlines.description)

gives: [('deliverydate', <class 'datetime.date'>, 11, 9, 9, 0, True)]给出: [('deliverydate', <class 'datetime.date'>, 11, 9, 9, 0, True)]

I also tried:我也试过:

pandas.read_sql(query,db,parse_dates={'DeliveryDate': {"dayfirst": True}})

(dates are eg 27-6-2022) Which unfortunately gives the same error. (日期例如 27-6-2022)不幸的是,这给出了同样的错误。

Any help would be appreciated, cheers,任何帮助将不胜感激,欢呼,

SELECT CAST(DeliveryDate AS varchar(12)) AS dd FROM Orders …

(正如对该问题的评论中所建议的)解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM