Re: [SQL] Rules with Conditions: Bug, or Misunderstanding

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Joel Burton" <jburton(at)scw(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Rules with Conditions: Bug, or Misunderstanding
Date: 2000-11-30 00:42:53
Message-ID: 19579.975544973@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

"Joel Burton" <jburton(at)scw(dot)org> writes:
> create rule dev_ins as on update to dev_col_comments where
> old.description isnull do instead insert into pg_description ( objoid,
> description) values (old.att_oid, new.description);

> create rule dev_upd as on update to dev_col_comments where
> old.description notnull do instead update pg_description set
> description=new.description where objoid=old.att_oid;

> This doesn't work: I get a "cannot update view w/o rule" error
> message, both for fields where description was null, and for fields
> where it wasn't null.

Hm. Perhaps the "cannot update view" test is too strict --- it's not
bright enough to realize that the two rules together cover all cases,
so it complains that you *might* be trying to update the view. As the
code stands, you must provide an unconditional DO INSTEAD rule to
implement insertion or update of a view.

I'm not sure this is a big problem, though, because the solution is
simple: provide an unconditional rule with multiple actions. For
example, I think this will work:

create rule dev_upd as on update to dev_col_comments do instead
(
insert into pg_description (objoid, description)
select old.att_oid, new.description WHERE old.description isnull;
update pg_description set description=new.description
where objoid = old.att_oid;
)

but I haven't tried it...

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mikheev, Vadim 2000-11-30 01:35:23 RE: xlog_bufmgr
Previous Message Tom Lane 2000-11-30 00:25:17 Re: [GENERAL] Warning: Don't delete those /tmp/.PGSQL.* files

Browse pgsql-sql by date

  From Date Subject
Next Message Philip Warner 2000-11-30 00:44:42 Re: Subselect in join?
Previous Message Kenn Thompson 2000-11-30 00:24:39 Subselect in join?