Re: Multiple Rules :: Postgres Is confused !!
От | Najib Abi Fadel |
---|---|
Тема | Re: Multiple Rules :: Postgres Is confused !! |
Дата | |
Msg-id | 003201c4a6bf$48919000$f664a8c0@najib обсуждение исходный текст |
Ответ на | Multiple Rules :: Postgres Is confused !! ("Najib Abi Fadel" <nabifadel@usj.edu.lb>) |
Ответы |
Re: Multiple Rules :: Postgres Is confused !!
|
Список | pgsql-general |
> ALL rules get executed. Conditions get combined (actually, parse trees > get merged). > > === BEGIN rule_test.sql === > CREATE TABLE foo (a int4 PRIMARY KEY, b text); > > COPY foo FROM stdin; > 1 aaa > 2 bbb > 3 ccc > 4 aaa > 5 bbb > 6 ccc > \. > > CREATE VIEW foo_v AS SELECT * FROM foo WHERE b='bbb'; > > CREATE RULE foo_v_upd1 AS ON UPDATE TO foo_v DO INSTEAD > UPDATE foo SET b = 'z' || NEW.b WHERE a = OLD.a; > > SELECT * FROM foo ORDER BY a; > > UPDATE foo_v SET b='xxx'; > > SELECT * FROM foo ORDER BY a; > === END rule_test.sql === > > This will update 2 rows (those with b='bbb') since we impose no WHERE in > our update but the view does. The OLD/NEW refer to target rows > before/after the change. > > Does that make things clearer? > -- If i am getting this right the update command: "UPDATE foo_v SET b='xxx';" will first get the "a" values (2 and 5) from the view and then execute the update on this rows. ? So im my case, when i call the update : "update transactions_sco_v set traiter='t' where id = 53597;" IF select cursus_id, vers_id, traiter, code_type_academic, cod_etu from transactions_sco_v where id = 53597; Returns -[ RECORD 1 ]------+------- cursus_id | 62 vers_id | 6 traiter | f code_type_academic | ECT cod_etu | 041400 this will execute the 3 update corresponding to the 3 rules i defined for the values of cursus_id, vers_id, traiter, code_type_academic, cod_etu returned above !!! and i will have the following 3 updates executes ! UPDATE transactions_sco SET traiter = 't' WHERE cursus_id = 62 AND vers_id = 6 traiter = 'f' AND code_type_academic = 'ECT' and cod_etu = '041400'; UPDATE transactions_sco SET traiter = 't' WHERE cursus_id = 62 AND vers_id = 6 traiter = 'f' AND code_type_academic = 'ECT'; UPDATE transactions_sco SET traiter = 't' WHERE id = 53597; I AM GETTING THIS RIGHT ?? THANX AGAIN FOR YOUR HELP.
В списке pgsql-general по дате отправления: