0

当我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从我要上传的记录中引用。

有什么解决办法吗?谢谢!

4

1 回答 1

1

嗨,克雷格(欢迎其他人;))

非常感谢。你让我明白了,但删除规则有一些问题。第一条规则工作正常,所以我可以上传基于子查询的字段 grado。但是 calcularGrado2_view 规则不能使工作..

CREATE RULE calcularGrado_view AS ON INSERT TO lineamientos_sitios_view DO INSTEAD (

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;

);

CREATE RULE calcularGrado2_view AS ON DELETE TO lineamientos_sitios_view DO INSTEAD (

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=old.id_sitio) where id_sitio=old.id_sitio;

);

你知道这个规则有什么问题吗?谢谢!

于 2013-01-25T02:56:45.453 回答