2014-03-24 44 views
1

在Postgres 9.3.3中,我有一个物化视图,它可以执行一些繁重的计算。我想使用连接到原始表的物化视图来确定改变其状态的值。我如何使用Postgres中的更新连接来完成此操作?Postgres:更新表与物化视图结合?错误:视图无法在物化视图中锁定行


UPDATE account 
    SET status = 3 
FROM account a 
    JOIN mv_account mv ON mv.id = a.id 
WHERE mv.very_long_calc = true 

ERROR: cannot lock rows in materialized view "mv_account" 
SQL state: 42809 

回答

2

可能与此错误:

http://www.postgresql.org/message-id/[email protected]om

And probably fixed in 9.3.4:

Allow materialized views to be referenced in UPDATE and DELETE commands (Michael Paquier)

Previously such queries failed with a complaint about not being able to lock rows in the materialized view.

没有理由自连接。只要做:

update account a 
set status = 3 
from mv_account mv 
where mv.id = a.id and mv.very_long_calc