Forgot your password?
typodupeerror
Databases

PostgreSQL 9.3 Will Feature UPDATEable Views 68

Posted by Unknown Lamer
from the long-overdue-features dept.
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.
This discussion has been archived. No new comments can be posted.

PostgreSQL 9.3 Will Feature UPDATEable Views

Comments Filter:
  • Re:Good use-case? (Score:4, Informative)

    by magarity (164372) on Wednesday December 12, 2012 @01:19PM (#42262375)

    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)

    by jellomizer (103300) on Wednesday December 12, 2012 @01:23PM (#42262429)

    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)

    by Anonymous Coward on Wednesday December 12, 2012 @01:25PM (#42262465)

    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.

  • by mobby_6kl (668092) on Wednesday December 12, 2012 @01:26PM (#42262473)

    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:

    • The view must have exactly one entry in its FROM, which must be a table or another updatable view.
    • The view definition must not contain WITH, DISTINCT, GROUP BY, HAVING, LIMIT, or OFFSET clauses at the top level.
    • The view definition must not contain set operations (UNION, INTERSECT or EXCEPT) at the top level.
    • All columns in the viewâ(TM)s select list must be simple references to columns of the underlying relation. They cannot be expressions, literals or functions. System columns cannot be referenced, either.
    • No column of the underlying relation can appear more than once in the viewâ(TM)s select list.
    • The view must not have the security_barrier property.
  • Re:Good use-case? (Score:5, Informative)

    by Anrego (830717) * on Wednesday December 12, 2012 @01:40PM (#42262699)

    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)

    by ArsenneLupin (766289) on Wednesday December 12, 2012 @01:46PM (#42262755)

    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.

  • by schmiddy (599730) on Wednesday December 12, 2012 @01:52PM (#42262829) Homepage Journal
    Materialized views are on the way, hopefully for 9.3 [postgresql.org]. The first pass at this is fairly limited, you have to refresh the matview yourself (i.e. it supports only the "snapshot" type of matview maintenance, per terminology here [jonathangardner.net]).

Save energy: Drive a smaller shell.

Working...