使用SQLite UPSERT语法报错:no such column: excluded.ComputerName
SQLite UPSERT 报错"no such column: excluded.ComputerName"的解决方法
问题出在excluded行的列名引用错误:excluded代表的是拟插入目标表的那一行数据,它的列名与**目标表(Computers)**的列名完全一致,而非SELECT子句里源表(DataImport)的列名。
你在INSERT语句中把DataImport.ComputerName映射到了Computers.Name,所以excluded里对应的列是excluded.Name,不是excluded.ComputerName。
修正后的SQL语句如下:
INSERT INTO Computers (Name, Model, SerialNumber) SELECT ComputerName, Model, SerialNumber FROM DataImport WHERE true ON CONFLICT(SerialNumber) DO UPDATE SET Name = excluded.Name WHERE length(excluded.Name) > length(Name)
简单来说,excluded的结构完全复刻目标表,引用时必须用目标表的列名,不能用源表的别名或原列名。
内容的提问来源于stack exchange,提问作者Ed R.
相关产品推荐
相关产品推荐

