Search Postgresql Archives

Re: CREATE RULE on VIEW with INSERT after UPDATE does not work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Peter Marius" <Peter.Marius@xxxxxx> writes:
> I thought, the example with "mylog" would be better to
> demonstrate the problem, but it's missing the point.
> Below, if have added the code with my real problem.

> CREATE RULE sru AS ON UPDATE TO myview DO INSTEAD
> (
>   UPDATE mytable SET stop = now() WHERE id = old.id AND stop IS null; 
>   INSERT INTO myview (id, proc, start, stop) VALUES (old.id, old.proc, now(), null);
> );

AFAICS, all you need to do is swap the ordering of those two operations.

It might help to understand that what you write as an INSERT/VALUES is
really more like INSERT ... SELECT ... FROM myview WHERE ..., the WHERE
condition being the same as was given in the "UPDATE myview" command
that the rule rewrites.  As soon as you change the stop value in the
UPDATE mytable, the SELECT from the view will find nothing.

			regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux