python - sqlite 有没有办法在列中插入新值时插入精确值作为主键或其他默认值?
问题描述
我相信必须首先创建该行以获得自增PK。然后我可以用生成的 PK 值替换一列。但我没有得到正确的结果。
insert = "insert into table(name, status) values (:Name, :Status)
params = {'Name': Jack,
'status' : active
}
db.execute(insert, params)
db.commit()
insert_type = "replace into table (type) values (select id from table)"
db.execute(insert_type)
db.commit()
所以表确实有列作为 id(自动增量)、名称、状态和类型(默认 0 或 id)将主键列值插入同一个表中的非主键列。
解决方案
我认为您可以使用 DEFUALT = blank 为任何列创建默认值。
推荐阅读
- android - ARCore Augmented Image 如何在运行时创建新的对象渲染器
- java - 学习 Java 中的继承,不确定如何正确使用 super.toString()?
- python - 如何阻止 tkinter 进行文本换行?
- c# - C#:将 xml 文件转换为 csv 文件
- eclipse - 无法推送到 Git
- android - Android Studio - UIThread,如何停止重载?
- c++ - 尝试处理大型数组时 Eclipse 中的终止错误
- sql - 为什么 groupby 查询会产生语法错误
- r - 按组获取子图并计算 R 中的网络模块化
- jquery - 为什么“PrimitiveValue”或“StartObject”节点是预期错误