On 7/25/06, Bernd Helmle <[EMAIL PROTECTED]> 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 view vtest_serial as select * from testing_serial;

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

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

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 

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


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.

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

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not

Reply via email to