ERROR: column “a“ of relation “table2“ does not exist

2023-10-17 08:50:17 浏览数 (2)

一、背景

pg执行update select时报错

ERROR:  column "a" of relation "table2" does not exist

二、执行语句

UPDATE table1 a SET a.order_no =b.order_no from table2 b   WHERE  b.serial_no = a.order_no

三、定位原因

set不能使用别名,即使定义了别名也不生效

四、解决方案

UPDATE table1 a SET order_no =b.order_no from table2 b   WHERE  b.serial_no = a.order_no;

五、模板示例

update 待更新表 a

set 待更新表_字段一 = b.字段一

from 关联表 b

where a.关联字段= b.关联字段

;

0 人点赞