pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSequence in the rules
2+ messages / 2 participants
[nested] [flat]
* Sequence in the rules
@ 2002-02-18 12:10 Luis Sousa <llsousa@ualg.pt>
0 siblings, 1 reply; 2+ messages in thread
From: Luis Sousa @ 2002-02-18 12:10 UTC (permalink / raw)
To: pgsql-sql
Hi everybody
I'm running on Postgresql 7.1.3.
I have four rules for update for a view, whose definition are:
-- UPDATE0
CREATE RULE "infoturno_r_update0" AS ON UPDATE TO "infoturno"
DO INSTEAD NOTHING;
-- UPDATE1
CREATE RULE "infoturno_r_update1" AS ON UPDATE TO "infoturno"
WHERE NEW.cod_disciplina != OLD.cod_disciplina
OR NEW.var != OLD.var
OR NEW.tipo != OLD.tipo
OR NEW.turno != OLD.turno
DO INSTEAD (
SELECT
infoturno_f_update1(OLD.id_e,NEW.cod_disciplina,NEW.var,NEW.tipo,NEW.turno,OLD.grau,OLD.curso,OLD.ramo,OLD."anoCurricular",OLD."anoLectivo")
AS ok;
);
-- UPDATE2
CREATE RULE "infoturno_r_update2" AS ON UPDATE TO "infoturno"
WHERE NEW.grau != OLD.grau
OR NEW.curso != OLD.curso
OR NEW.ramo != OLD.ramo
OR NEW."anoCurricular" != OLD."anoCurricular"
DO INSTEAD (
SELECT
infoturno_f_update2(OLD.id_e,OLD.grau,OLD.curso,OLD.ramo,OLD."anoCurricular",NEW.grau,NEW.curso,NEW.ramo,NEW."anoCurricular",OLD."anoLectivo")
AS ok;
);
-- UPDATE3
CREATE RULE "infoturno_r_update3" AS ON UPDATE TO "infoturno"
WHERE (NEW.cod_disciplina != OLD.cod_disciplina
OR NEW.var != OLD.var
OR NEW.tipo != OLD.tipo
OR NEW.turno != OLD.turno)
AND (NEW.grau != OLD.grau
OR NEW.curso != OLD.curso
OR NEW.ramo != OLD.ramo
OR NEW."anoCurricular" != OLD."anoCurricular")
DO INSTEAD (
SELECT test1() AS ok1;
SELECT test2() AS ok2;
SELECT
infoturno_f_update1(OLD.id_e,NEW.cod_disciplina,NEW.var,NEW.tipo,NEW.turno,OLD.grau,OLD.curso,OLD.ramo,OLD."anoCurricular",OLD."anoLectivo")
AS ok;
SELECT
infoturno_f_update2(OLD.id_e,OLD.grau,OLD.curso,OLD.ramo,OLD."anoCurricular",NEW.grau,NEW.curso,NEW.ramo,NEW."anoCurricular",OLD."anoLectivo")
AS ok;
);
The rule infoturno_r_update3 must run both functions when that condition
happens, but the problem is that the first rule that is runned is
infoturno_r_update1. When it passes in the rule infoturno_r_update3, the
condition isn't already true, because the values were changed inside the
rule that runned.
How can I define that the first rule to be checked is
infoturno_r_update3 and then it tries the others ?
Thanks in advance.
PS: I hope it's clear the definition that I use for the rules.
Luis Sousa
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Sequence in the rules
@ 2002-02-18 15:33 Tom Lane <tgl@sss.pgh.pa.us>
parent: Luis Sousa <llsousa@ualg.pt>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2002-02-18 15:33 UTC (permalink / raw)
To: Luis Sousa <llsousa@ualg.pt>; +Cc: pgsql-sql
Luis Sousa <llsousa@ualg.pt> writes:
> How can I define that the first rule to be checked is
> infoturno_r_update3 and then it tries the others ?
You can't. Instead consider making a single, multi-action rule
that does the actions in the right sequence.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-02-18 15:33 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-18 12:10 Sequence in the rules Luis Sousa <llsousa@ualg.pt>
2002-02-18 15:33 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox