跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Python] 大佬们,请教一个 Python 下关于 duckdb 的数据导入很诡异的问题,困扰了我两天,不胜感激。

发表于

大佬们,请教一个 Python 下关于 duckdb 的数据导入很诡异的问题,困扰了我两天,不胜感激。

背景: 最近在搞一个小爬虫,用到了 duckdb 需要在导入的时候进行去重更新,因为导入的时候跨越数据时间久远无法在代码中就实现去重,只能通过 duckdb 的数据库机制去重 表结构如下 CREATE TABLE IF NOT EXISTS ticai ( "一级类目" TEXT, "一级类目" TEXT, "人数" BIGINT, UNIQUE("一级类目", "一级类目"))

data_df 为一个 frame columns 为列名 placeholders 为占位符个数

代码: #拼接导入语句 INSERT OR REPLACE INTO 将现有行的每一列更新为要插入的行的新值 sql_str = f'"""INSERT OR REPLACE INTO ticai ({columns}) VALUES ({placeholders})"""' #duckdb 执行批量导入 con.executemany(sql_str, data_df.values.tolist())

症状: 使用拼接语句执行 con.executemany ()就一直报错,结果如下 duckdb.duckdb.ParserException: Parser Error: syntax error at or near """"INSERT OR REPLACE INTO ticai (""

但是使用打印出来的 sql_str 拼接语句就能执行成功 con.executemany("""INSERT OR REPLACE INTO ticai ("一级类目", "二级类目", "人数") VALUES (?, ?, ?)""", data_df.values.tolist()) 结果如下:<duckdb.duckdb.DuckDBPyConnection object at 0x000001586624C2F0>

超级诡异,我不是很精通 Python ,也木有在其他平台找到问题的症结,球球大佬们帮忙解答下

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.