sqlite3:表名可以替换为吗?

时间:2018-10-11 06:49:23

标签: python-3.x sqlite

如何用替换表名? ,就像这样:

c.execute("CREATE TABLE if not exists ?(id integer,name text)",(tablename,))
c.execute("INSERT INTO ? (id) VALUES(1)",(tablename,))

2 个答案:

答案 0 :(得分:0)

尝试一下;

renameTable = "ALTER TABLE old RENAME TO new"

cursor.execute(renameTable)

答案 1 :(得分:0)

感谢大家,我发现我可以这样做:

str = "INSERT INTO %s(id) VALUES (1)"
c.execute(str%s)

表名不能替换为:?