我目前正在從 SQL Server 遷移到 PostgreSQL,并且對 postgres 中的更新查詢感到困惑。
我在 SQL Server 中有這樣的查詢:
UPDATE t1
SET col1 = 'xx'
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.id
WHERE t2.id is null
你如何在 postgres 中做到這一點?
提前致謝
uj5u.com熱心網友回復:
左連接用于模擬“NOT EXISTS”條件,因此您可以將其重寫為:
update table1 t1
set col1 = 'xx'
where not exists (select *
from table2 t2
where t1.id = t2.id);
作為一個方面說明:Postgres的作業方式是不同的SQL Server和一般你應該不重復UPDATE陳述句的目標表在FROM子句中的Postgres。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/317107.html
標籤:PostgreSQL
上一篇:資料透視表/交叉表PostgreSQL錯誤:無效的回傳型別
下一篇:如何使用python查詢資料庫
