当我id_sitio
用实际值替换时,我可以更新基于子查询的字段:
update sitios
set grado = (
select count(lin_sit.id_lineamiento) as total
from lineamientos_sitios lin_sit inner join sitios sit on lin_sit.id_sitio=sit.id_sitio
where sit.id_sitio=1418
)
where id_sitio=1418;
但不是在我实施规则时。
CREATE or replace RULE actualizar_lineamientos_sitios_view AS ON UPDATE TO lineamientos_sitios_view DO INSTEAD (
UPDATE lineamientos_sitios SET id_lineamiento = new.id_lineamiento, id_sitio = new.id_sitio WHERE (lineamientos_sitios.id_lineamiento = old.id_lineamiento AND lineamientos_sitios.id_sitio = old.id_sitio);
update sitios set grado = (select count(lin_sit.id_lineamiento) as total from lineamientos_sitios lin_sit inner join sitios sit on lin_sit.id_sitio=sit.id_sitio where sit.id_sitio=new.id_sitio) where id_sitio=new.id_sitio;
);
我相信第一次更新是无关紧要的,因为它有效,我不确定如何id
从我要上传的记录中引用。
有什么解决办法吗?谢谢!