You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 06:55:24