【问题标题】:Pandas to_sql creating table but not inserting dataPandas to_sql 创建表但不插入数据
【发布时间】:2022-01-09 23:28:14
【问题描述】:

我正在使用 Oracle,并且我看到了在架构中创建的表(尽管所有表都包含 VARCHAR 的 CLOB 列)。但是没有数据被插入?数据框中确实有数据。

engine = create_engine('oracle+cx_oracle://user:password@host:1521/?service_name=myservice', max_identifier_length=128)
df = get_registrations()
df.to_sql(name='pandas_registrations', con=engine, if_exists='replace', chunksize=1000, schema='ANALYTICS', method=None)

我读到这里不需要 commit() Does the Pandas DataFrame.to_sql() function require a subsequent commit()?

【问题讨论】:

  • 好吧,我在没有 con.commit() 的情况下让它工作了。我不得不替换 clob 并在连接上设置自动提交。在任何示例中都没有描述这些内容。老实说,我不确定哪一个解决了这个问题。

标签: python pandas cx-oracle


【解决方案1】:

我遇到了类似的问题并切换到 sqlalchemy 而不是 cx_Oracle,因为引擎在我的场景中有所帮助。

【讨论】:

  • 我正在使用 sqlalchemy create_engine,只使用 oracle 驱动程序?
  • SQLAlchemy 使用 cx_Oracle!
  • 那么我的驱动字符串会是什么样子?
猜你喜欢
  • 2018-06-26
  • 2020-12-01
  • 2022-01-22
  • 2015-10-18
  • 2019-05-24
  • 2020-10-21
  • 2015-09-01
  • 2022-08-02
  • 1970-01-01
相关资源
最近更新 更多