Thread: Re: [SQL] CREATE RULE ON UPDATE/DELETE

Re: [SQL] CREATE RULE ON UPDATE/DELETE

From
Tom Lane
Date:
Joel Burton <joel@joelburton.com> writes:
> CREATE VIEW dbl AS SELECT id * 2 as id, name FROM raw;

> CREATE RULE dbl_update AS ON UPDATE TO dbl DO INSTEAD UPDATE raw SET
> id = NEW.id, name = NEW.name WHERE OLD.id = id;

Surely you'd need something like

CREATE RULE dbl_update AS ON UPDATE TO dbl DO INSTEAD UPDATE raw SET
id = NEW.id / 2, name = NEW.name WHERE OLD.id = id * 2;

(untested...)
        regards, tom lane


Re: [SQL] CREATE RULE ON UPDATE/DELETE

From
"Aasmund Midttun Godal"
Date:
Yes, I agree perfectly... I never thought of that! I would really like it if some more info was added to the docs
regardinginfo on rules and triggers. The section on update rules is quite good, but some more would never hurt. One
pointin the trigger vs rules section which at least to me is very important is the simple fact that you cannot have a
triggeron a select... Ok I understand why - but it took some time...
 

Thank you for answering my questions!

regards,

Aasmund.
On Sun, 21 Oct 2001 12:47:41 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Joel Burton <joel@joelburton.com> writes:
> 
> 
> Surely you'd need something like
> 
> CREATE RULE dbl_update AS ON UPDATE TO dbl DO INSTEAD UPDATE raw SET
> id = NEW.id / 2, name = NEW.name WHERE OLD.id = id * 2;
> 
> (untested...)
> 
>             regards, tom lane

Aasmund Midttun Godal

aasmund@godal.com - http://www.godal.com/
+47 40 45 20 46


Re: [SQL] CREATE RULE ON UPDATE/DELETE

From
Bruce Momjian
Date:
I have added the following text to the CREATE TRIGGER manual page to
address this issue.  It often confuses people so it is good to point
out:
 <para> <command>SELECT</command> does not modify any rows so you can not create <command>SELECT</command> triggers.
</para>


---------------------------------------------------------------------------

> Yes, I agree perfectly... I never thought of that! I would really like it if some more info was added to the docs
regardinginfo on rules and triggers. The section on update rules is quite good, but some more would never hurt. One
pointin the trigger vs rules section which at least to me is very important is the simple fact that you cannot have a
triggeron a select... Ok I understand why - but it took some time...
 
> 
> Thank you for answering my questions!
> 
> regards,
> 
> Aasmund.
> On Sun, 21 Oct 2001 12:47:41 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > Joel Burton <joel@joelburton.com> writes:
> > 
> > 
> > Surely you'd need something like
> > 
> > CREATE RULE dbl_update AS ON UPDATE TO dbl DO INSTEAD UPDATE raw SET
> > id = NEW.id / 2, name = NEW.name WHERE OLD.id = id * 2;
> > 
> > (untested...)
> > 
> >             regards, tom lane
> 
> Aasmund Midttun Godal
> 
> aasmund@godal.com - http://www.godal.com/
> +47 40 45 20 46
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026