From: | "Jaime Casanova" <systemguards(at)gmail(dot)com> |
---|---|
To: | "Bernd Helmle" <mailings(at)oopsware(dot)de> |
Cc: | pgsql-patches(at)postgresql(dot)org |
Subject: | Re: Patch for updatable views |
Date: | 2006-07-25 23:29:39 |
Message-ID: | c2d9e70e0607251629u5080b7ccife7c62cba0f1669d@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
On 7/25/06, Bernd Helmle <mailings(at)oopsware(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2006-07-26 00:34:11 | Re: [Fwd: Re: Patch for - Change LIMIT/OFFSET to use int8] |
Previous Message | Bruce Momjian | 2006-07-25 23:23:45 | pgsql: /contrib/cube improvements: Update the calling convention for |