Re: Patch for updatable views - Mailing list pgsql-patches
From | Jaime Casanova |
---|---|
Subject | Re: Patch for updatable views |
Date | |
Msg-id | c2d9e70e0607251629u5080b7ccife7c62cba0f1669d@mail.gmail.com Whole thread Raw |
In response to | Patch for updatable views (Bernd Helmle <mailings@oopsware.de>) |
Responses |
Re: Patch for updatable views
|
List | pgsql-patches |
On 7/25/06, Bernd Helmle <mailings@oopsware.de> wrote: > Hi folks, > > please find attached an implementation for updatable views. Included are > support for pg_dump and information_schema, regression test and > documentation are missing. Also, there's currently no upgrade path for older > PostgreSQL versions and user defined rules on views. i'm testing the functionality... seems good to me... i will work on docs and regress if no one objects and bernd is not doing it... ------------ AFAICS, the view will not be updateable if there are casts in the select list (seems fair to let that to future revisions), but i think we must say it. ------------ One thing to think of: create table testing_serial (id serial primary key, name text); CREATE TABLE create view vtest_serial as select * from testing_serial; CREATE VIEW insert into vtest_serial values (default, 'name1'); psql:../view_test.sql:81: ERROR: null value in column "id" violates not-null constraint insert into vtest_serial(name) values ('name2'); psql:../view_test.sql:82: ERROR: null value in column "id" violates not-null constraint i still think that in updateable views we need to inherit the defaut value of the base table, i still see this code commented in rewriteHandler.c ------------ psql:../view_test.sql:73: ERROR: cannot insert into a view HINT: You need an unconditional ON INSERT DO INSTEAD rule. BTW, we must change this message for something more like 'cannot insert into a non updateable view' ------------- + /* + * I will do this only in case of relkind == RELKIND_VIEW. + * This is the last attempt to get a value for expr before we + * consider that expr must be NULL. + */ + /* if (expr == NULL && rel->rd_rel->relkind == RELKIND_VIEW) */ + /* { */ + /* expr = (Node *)makeNode(SetToDefault); */ + /* return expr; */ + /* } */ + if this functionality will be accepted this is the time to discuss it otherwise drop this comment. With this code we still can create a different default for the view with ALTER TABLE ADD DEFAULT ------------ > I have some code which drops the implicit created rules silently if someone > wants to have its own rule, but this needs some discussion, i think. > + #if 0 + /* + * Implicit rules should be dropped automatically when someone + * wants to have its *own* rules on the view. is_implicit is set + * to NO_OPTION_EXCPLICIT in this case so we drop all implicit + * rules on the specified event type immediately. + * + * ???FIXME: do we want this behavior??? + */ + + if ( ev_kind == NO_OPTION_EXPLICIT ) + deleteImplicitRulesOnEvent(event_relation, event_type); + #endif This is a must for compatibility with older versions. Otherwise we will have views with user defined rules and implicit rules that will have an unexpected behaviour. ------------ > The patch covers the whole SQL92 functionality and doesn't create any > rules, if a given view is considered not to be compatible with SQL92 definitions. I think is necessary to send some NOTICE when we can't create rules at all or when we can't create one of them (insert rules are not always created because they need all not-null without defaults columns to be in the select list) ------------ > The supported > syntax is > > CREATE VIEW foo AS .... [ WITH [ CASCADED | LOCAL ] CHECK OPTION ] > > The check option is implemented as a conditional rule with a simple system > function, which checks the given expression tree to be true or false and raises > an error in the latter case. the check option is working for all cases i'm trying... > Also, i have dropped support for updatable views which contains indexed array > fields of tables (like SELECT foo[3], foo[2] FROM bar). These are treated > non-updatable and someone needs his own rules here. > -- regards, Jaime Casanova "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the universe trying to produce bigger and better idiots. So far, the universe is winning." Richard Cook
pgsql-patches by date: