Thread: updating on views

updating on views

From
"XiaojingLi"
Date:
Hi!I'd like to bother you with something about updating views. At present, postgresql7.3 doesn't support update on
views.WhenI look up the source code, I see that view is implemented with rules. That is when a view is created, a
corresponding‘select' rule is created too. And I see the following code: 

#ifdef NOTYETRuleStmt   *replace_rule;RuleStmt   *append_rule;RuleStmt   *delete_rule;
#endif
.. ...

#ifdef NOTYETreplace_rule = FormViewReplaceRule(view, viewParse);append_rule = FormViewAppendRule(view,
viewParse);delete_rule= FormViewDeleteRule(view, viewParse); 
#endif
.. ...
In my eyes, it is not very difficult to realize view update with fill the above three functions。But I know the
developersof postgresql are very learned, now that they didn't realize view update, maybe it is very difficult. I am a
beginnerof postgresql, so with my limited knowlege, maybe  I can't realize the difficulity of doing such a thing. 
So I wonder if some of you would like to give me some advice about updating on views or why it is not realized、what's
thedifficulty of doing it? 
   Long for your reply.Thank you!

Best regards!



        

        Yours XiaojingLi
        qqjasmine@hotmail.com
          2002-11-23





Re: updating on views

From
Stephan Szabo
Date:
On Wed, 27 Nov 2002, XiaojingLi wrote:

>     I'd like to bother you with something about updating views. At
> present, postgresql7.3��doesn't support update on views.When I look up

It does if you provide the rules for what it means to do the update (and
there are some wierd issues with delete, but it is possible to get around
them)

>     In my eyes, it is not very difficult to realize view update with
> fill the above three functions��But I know the developers of
> postgresql are very learned, now that they didn't realize view update,
> maybe it is very difficult. I am a beginner of postgresql, so with my
> limited knowlege, maybe I can't realize the difficulity of doing such
> a thing. So I wonder if some of you would like to give me some advice
> about updating on views or why it is not realized��what's the
> difficulty of doing it?

Well, it depends.  SQL updatable views are fairly limited from what I
remember and the general write your own update rules is much broader, so I
doubt anyone got terribly excited by doing the limited version. It would
take some work to define what sort of view queries are acceptable for what
sort of updates and then make the appropriate rules (imagine queries with
set value functions or UNION) without knowledge outside of the view query.




Re: updating on views

From
Gavin Sherry
Date:
On Tue, 26 Nov 2002, Stephan Szabo wrote:

> Well, it depends.  SQL updatable views are fairly limited from what I
> remember and the general write your own update rules is much broader, so I
> doubt anyone got terribly excited by doing the limited version. It would
> take some work to define what sort of view queries are acceptable for what
> sort of updates and then make the appropriate rules (imagine queries with

SQL99 says that all columns in the view definition (ie, the SQL query
which defines the view) must also be updateable. This, of course,
requires some checking. We could do this here. I think, however, that it
would be much cleaner to implement this correctly through the planner and
executor instead of hacking it through the rewriter. Of course, that means
lots of code. 

Insertable-into and updateable views are certainly a very important
feature which Postgres is lacking. Maybe we should implement this the easy
way first and then, to increase performance, correctly -- at some later
point.

Gavin