Postgresql 连表更新字段语法 update

下面这段sql本来目的是想更新条件下的数据,可是这段sql却更新了整个表的数据。sql如下:

UPDATE tops_visa.visa_order
SET op_audit_abort_pass_date = now()
FROM
	tops_visa.visa_order as  t1
INNER JOIN tops_visa.visa_visitor as t2 
ON t1. ID = t2.order_id
WHERE
	t1.op_audit_abort_pass_date IS NULL
AND (
	t2. STATE = 'pch_abort_op_audit_pass'
	OR t2. STATE = 'pvd_abort_op_audit_pass'
)

 

正确的写法有多种,如下方法也能够实现正确的数据库修改:

 

UPDATE tops_visa.visa_order as t1
SET op_audit_abort_pass_date = now()
FROM
	tops_visa.visa_visitor AS t2
WHERE
	t1.ID = t2.order_id
AND t1.op_audit_abort_pass_date IS NULL
AND (
	t2. STATE = 'pch_abort_op_audit_pass'
	OR t2. STATE = 'pvd_abort_op_audit_pass'
)

 

你可能感兴趣的:(PostgreSQL)