某某潮流网,最新潮鞋资讯分享!

微信号:weixin888

SQLite - can I use placeholder for table names?

时间:2025-09-23 16:58人气:编辑:佚名

I'm looping and with each loop I manipulate data and then save it to different CSV file. Now I'm trying to do the same with SQLite. I have many tables but for sake of simplicity, lets say i have 3 tables: first_table, second_table, third_table

So say I properly connect to database file, create cursor, generate data i want to save, I generate proper table names for each loop, to save data into each table, see simplified code bellow:

tables=['first', 'second', 'third']

for each in tables:
    table_name=each + '_table'   # generated proper table name

    c.execute("INSERT OR IGNORE INTO table_name VALUES (?,?,?)", data)
    c.execute("INSERT OR IGNORE INTO" table_name "VALUES (?,?,?)", data)

I can't figure out, how to use variable: "table_name" as placeholder for previously generated table name. Above I'm showing two examples I tried, but of course both returns error.

Can anyone help me with this, please?

Edit: Not sure I managed to explain properly. Say I have 50 tables with names from: first_table to fiftieth_table. I will loop over 50 times, to insert into each table some data. (i need to loop 50 times since that's how i'm getting data). After every loop, I'm inserting into next table. How do I manage to change table name in c.execute("INSERT... statement for every loop?

标签: me   in  
相关资讯
热门频道

热门标签

官方微信官方微博百家号

网站简介 | 意见反馈 | 联系我们 | 法律声明 | 广告服务

Copyright © 2002-2022 天富平台-全球注册登录站 版权所有 备案号:粤ICP备xxxxxxx号

平台注册入口