
PostgreSQL 9.3 Will Feature UPDATEable Views 68
Picking up work abandoned around Postgres 8.2, a patch recently hit the PostgreSQL 9.3 branch that adds SQL-92 automatically updatable views. For many common cases, you will no longer have to write hairy triggers to fake UPDATE support (e.g. if you have a view that hides a few internal columns). Limitations currently include only supporting views with at most one table in the FROM clause. This complements the under-advertised INSTEAD OF trigger support added in 9.1.
Re:Good use-case? (Score:4, Informative)
Do any slashdotters know of a situation where an update-able view would be handy/ideal?
Teradata is usually set up so that every basic DML operation (insert, update, delete) is done via views.
An improvement (Score:4, Informative)
It is a nice feature... However I don't see it too useful for the way I work.
Being that if I have a view it is often because it needs to have many tables involved. And I would need to setup an on Insert or on Update rule on the view anyways.
Re:Good use-case? (Score:5, Informative)
it seemed like only trivial views could be updated
Sadly true, the UPDATE has to be merged with the SELECT the view is built from to give an executable SQL. That's not always trivial to do.
Do any slashdotters know of a situation where an update-able view would be handy/ideal?
AFAIK the most common uses are:
a) Providing restricted views of tables to users with lower privileges
(eg a view of a users table where a connected user can read username, email etc but not password hash)
b) Providing a view for backwards compatibility with older applications when a table schema is updated, to avoid breaking queries in the older application until it is updated.
That's a weirdly specific topic to post on /. (Score:4, Informative)
But nevertheless quite interesting. The idea of updatable views is certainly a good one, but it seems that the current limitations make this feature more or less useless for now:
Re:Good use-case? (Score:5, Informative)
Only two use cases I can see are restricting access to a subset of columns (in which case a server side procedure works fine), or to allow legacy apps to work within new schemas (although this sounds like a really messy solution, and has that whole "temporary fix that gets left in forever" feel to it).
Re:Good use-case? (Score:5, Informative)
Do any slashdotters know of a situation where an update-able view would be handy/ideal?
Two pre-existing applications accessing the same data, and each of them expects the data to be laid out in a (slightly different) schema.
So, define tables with a common physical representation of the data, and then define views to map that representation to each one of the application's expectations.
O, and only automatically updatable views have restrictions that make them useless. The INSTEAD OF trigger allows to make almost any view updatable, but you need to tell the DB how.
Re:What about materialized views? (Score:5, Informative)