sqlite3 python留空栏

时间:2018-11-26 06:54:01

标签: python sqlite insert

我创建了一个有8列的表,我只想插入小于列号的值。我怎样才能做到这一点?一个答案将不胜感激。

logback.xml

1 个答案:

答案 0 :(得分:0)

您应该能够只在VALUES子句中指定要为其提供数据的列:

INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning)
    VALUES (?, ?, ?)

您的Python代码:

c.execute("""INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning) VALUES (:empID, :time_in_morning, :time_out_morning)""")

以上内容可能不适用于SQLite(尽管它当然适用于MySQL)。您可以尝试的一种解决方法是使用占位符进行INSERT INTO ... SELECT

INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning)
SELECT ?, ?, ?;

这是该代码的Python代码:

c.execute("""INSERT INTO tb_transaction (empID, time_in_morning, time_out_morning) SELECT :empID, :time_in_morning, :time_out_morning""")