Subject Re: [firebird-support] Updatable views
Author Ann W. Harrison
Marcin Bury wrote:
>
> Can someone explain how updatable view works.

In version 1.x, they work differently depending on whether the
view is "naturally updateable". A "naturally updateable" view
is one without joins, aggregates, projection (distinct), or
grouping - like the one you describe. Update, insert, and
delete statements on naturally updateable views work exactly
as they would on base tables - both the operation and triggers
are executed.

Views with joins, aggregates, projection, or grouping
behave differently - the only actions taken on a insert,
update, or delete statement are the actions defined in
triggers.


In Firebird 1.x, the simplest way to disable natural updates
on simple view is to change the view to include a join to
a table with one row - RDB$DATABASE is a good choice.

For example to disable natural updates on a simple view
like this:

create view naturallyUpdateable (a, b, c) as
select a, b, c from table1

change the view definition to this:

create view triggerUpdateOnly (a, b, c) as
select t1.a, t1.b, t1.c
from table1 t1
joint rdb$database t2


The rules will change in V2.0, but the "join hack" will
continue to work.


Regards,


Ann