python - 使用 SQLalchemy 将整数加载到 PostgreSQL - 错误 Invalid input syntax for integer
问题描述
我有以下代码将 CSV 文件加载到 PostgreSQL 数据库中。它像这样工作得很好:
def Load_Data(file_name):
data = genfromtxt(file_name, delimiter=',', skip_header=1, dtype=[('curr', numpy.unicode_, 10),
('code', numpy.unicode_, 10),
('exp', numpy.unicode_, 10),
('cryp', numpy.unicode_, 10)])
return data.tolist()
Base = declarative_base()
class CurrencyDetails(Base):
__tablename__ = 'curr_det'
curr = Column(VARCHAR(10), primary_key=True)
code = Column(VARCHAR(10))
exp = Column(VARCHAR(10))
cryp = Column(VARCHAR(10), nullable=False)
但是 exp 列实际上是 Integer 数据类型,我更愿意使用整数类型创建表列 exp。我试过用
exp = Column(Integer)
但后来我得到了错误
DataError('(psycopg2.DataError) 整数的无效输入语法
源 csv 文件有一些空值'',我认为这是问题所在。我可以在不修改文件的情况下以某种方式加载整数吗?
非常感谢您的帮助!
解决方案
推荐阅读
- jquery - 如何获取具有选择性日期的 mongoos 数据
- javascript - 如何将 jquery 数据表导出限制为 1000 行
- r - 计算每个样本与组质心的 n 维欧几里德距离,并为 R 中的每个组选择最低的 3 个
- typescript - 如何仅使用打字稿打开/关闭 TS 文件中的 Foundation Modal 或选项卡(不使用 $ 访问变量)
- sql - 如何在sql中按指定的年月选择日期范围
- php - 如何将我的所有路线重定向到本地 laravel 中的 www 并同时生活
- ajax - 如何在ajax成功函数中使用for循环?
- scala - 无法将 DF 写为增量表我 spark 2.4.4 和 scala 2.12 java.lang.NoSuchMethodError: com.fasterxml.jackson.module.scala
- ant - 在 Sonar LTS 7.9.2 中使用 jacoco.exec 文件显示声纳代码覆盖率
- c++ - glLineWidth 替代方案?