使用ODBC从HFSQL数据库读取日期时的ValueError

发布于 2025-02-11 04:17:36 字数 765 浏览 2 评论 0原文

在一些挣扎中,我使用ODBC连接到HFSQL服务器。我已经尝试了pypyodbc和pyodbc。 我的目标是在数据中获得一些见解(并可视化某些方面)。

对于一些计划可视化,我需要读取一些数据,这些数据适用于大多数表和列。但是,当我尝试读取包含日期的列时,我会得到一个值:

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

所有行都包含一个有效的日期。

这是当前产生上述错误的代码:

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

db是数据库(与其他查询一起使用)

    print(deadlines.description)

给出:[' )

我还尝试了:(

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

日期是27-6-2022) 不幸的是,这给出了相同的错误。

任何帮助将不胜感激, 干杯,

With some struggles I connected to a hfsql server using ODBC. I've tried both pypyodbc and 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:

    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)

    print(deadlines.description)

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

I also tried:

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

(dates are e.g. 27-6-2022)
Which unfortunately gives the same error.

Any help would be appreciated,
cheers,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从﹋此江山别 2025-02-18 04:17:36
SELECT CAST(DeliveryDate AS varchar(12)) AS dd FROM Orders …

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

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

(as suggested in a comment to the question) solved the issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文