pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedview rules
3+ messages / 2 participants
[nested] [flat]
* view rules
@ 2001-12-06 20:17 Oleg Lebedev <olebedev@waterford.org>
2001-12-06 21:32 ` Re: view rules Ross J. Reedstrom <reedstrm@rice.edu>
0 siblings, 1 reply; 3+ messages in thread
From: Oleg Lebedev @ 2001-12-06 20:17 UTC (permalink / raw)
To: pgsql-sql
Hi everybody,
I am trying to create an update rule for a view. It's created fine, and
I can find it in pg_rules, but when I try to update the view, I get the
usual error:
ERROR: Cannot update a view without an appropriate rule.
My rule definitions is as follows:
CREATE RULE update_priority AS ON UPDATE TO progress_report
WHERE NEW.priority != OLD.priority
DO INSTEAD UPDATE activity SET priority=NEW.priority
WHERE activity.productcode = OLD.product_code
AND activity.actname=OLD.component;
I am trying to update the view as follows:
update progress_report set priority=2 where product_code='m3' and
component='act';
activity is a table. I can't figure out what's wrong. Please help.
thanks,
Oleg
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: view rules
2001-12-06 20:17 view rules Oleg Lebedev <olebedev@waterford.org>
@ 2001-12-06 21:32 ` Ross J. Reedstrom <reedstrm@rice.edu>
2001-12-06 22:14 ` Re: view rules Oleg Lebedev <olebedev@waterford.org>
0 siblings, 1 reply; 3+ messages in thread
From: Ross J. Reedstrom @ 2001-12-06 21:32 UTC (permalink / raw)
To: Oleg Lebedev <olebedev@waterford.org>; +Cc: pgsql-sql
On Thu, Dec 06, 2001 at 01:17:44PM -0700, Oleg Lebedev wrote:
> Hi everybody,
> I am trying to create an update rule for a view. It's created fine, and
> I can find it in pg_rules, but when I try to update the view, I get the
> usual error:
> ERROR: Cannot update a view without an appropriate rule.
>
> My rule definitions is as follows:
> CREATE RULE update_priority AS ON UPDATE TO progress_report
> WHERE NEW.priority != OLD.priority
> DO INSTEAD UPDATE activity SET priority=NEW.priority
> WHERE activity.productcode = OLD.product_code
> AND activity.actname=OLD.component;
>
> I am trying to update the view as follows:
> update progress_report set priority=2 where product_code='m3' and
> component='act';
>
The View/Rule system is very picky: you have to have rules to cover
_every_ possible update case before it'll allow any to go through.
The usual way aroun this is to create a 'do nothing' rule with no WHERE
clause:
ifs_test=# create rule update_any as ON UPDATE TO progress_report DO INSTEAD NOTHING;
ifs_test=# select * from progress_report;
priority | product_code | component
----------+--------------+-----------
1 | 3 | act
(1 row)
ifs_test=# update progress_report set priority=2 where product_code='3' and component='act';
UPDATE 1
ifs_test=# select * from progress_report;
priority | product_code | component
----------+--------------+-----------
2 | 3 | act
(1 row)
(I fudged your product code, since I'd created an int in my test case: if
you'd sent along schema for the table, my test would have gone _much_ faster)
Ross
--
Ross Reedstrom, Ph.D. reedstrm@rice.edu
Executive Director phone: 713-348-6166
Gulf Coast Consortium for Bioinformatics fax: 713-348-6182
Rice University MS-39
Houston, TX 77005
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: view rules
2001-12-06 20:17 view rules Oleg Lebedev <olebedev@waterford.org>
2001-12-06 21:32 ` Re: view rules Ross J. Reedstrom <reedstrm@rice.edu>
@ 2001-12-06 22:14 ` Oleg Lebedev <olebedev@waterford.org>
0 siblings, 0 replies; 3+ messages in thread
From: Oleg Lebedev @ 2001-12-06 22:14 UTC (permalink / raw)
To: Ross J. Reedstrom <reedstrm@rice.edu>; +Cc: pgsql-sql
Thanks a lot Ross,
that fixed my problem. I think it should be mentioned in PostgreSQL tutorial (in Al Bundy's
example).
thanks again,
Oleg
"Ross J. Reedstrom" wrote:
> On Thu, Dec 06, 2001 at 01:17:44PM -0700, Oleg Lebedev wrote:
> > Hi everybody,
> > I am trying to create an update rule for a view. It's created fine, and
> > I can find it in pg_rules, but when I try to update the view, I get the
> > usual error:
> > ERROR: Cannot update a view without an appropriate rule.
> >
> > My rule definitions is as follows:
> > CREATE RULE update_priority AS ON UPDATE TO progress_report
> > WHERE NEW.priority != OLD.priority
> > DO INSTEAD UPDATE activity SET priority=NEW.priority
> > WHERE activity.productcode = OLD.product_code
> > AND activity.actname=OLD.component;
> >
> > I am trying to update the view as follows:
> > update progress_report set priority=2 where product_code='m3' and
> > component='act';
> >
>
> The View/Rule system is very picky: you have to have rules to cover
> _every_ possible update case before it'll allow any to go through.
> The usual way aroun this is to create a 'do nothing' rule with no WHERE
> clause:
>
> ifs_test=# create rule update_any as ON UPDATE TO progress_report DO INSTEAD NOTHING;
>
> ifs_test=# select * from progress_report;
> priority | product_code | component
> ----------+--------------+-----------
> 1 | 3 | act
> (1 row)
>
> ifs_test=# update progress_report set priority=2 where product_code='3' and component='act';
> UPDATE 1
> ifs_test=# select * from progress_report;
> priority | product_code | component
> ----------+--------------+-----------
> 2 | 3 | act
> (1 row)
>
> (I fudged your product code, since I'd created an int in my test case: if
> you'd sent along schema for the table, my test would have gone _much_ faster)
>
> Ross
> --
> Ross Reedstrom, Ph.D. reedstrm@rice.edu
> Executive Director phone: 713-348-6166
> Gulf Coast Consortium for Bioinformatics fax: 713-348-6182
> Rice University MS-39
> Houston, TX 77005
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-12-06 22:14 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-12-06 20:17 view rules Oleg Lebedev <olebedev@waterford.org>
2001-12-06 21:32 ` Ross J. Reedstrom <reedstrm@rice.edu>
2001-12-06 22:14 ` Oleg Lebedev <olebedev@waterford.org>
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