Re: Composite types for updatable views

From: "DINESH NAIR" <Dinesh_Nair(at)iitmpravartak(dot)net>
To: Malthe <mborch(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Composite types for updatable views
Date: 2025-07-16 20:10:16
Message-ID: PN4P287MB4381C64F2E171B2FAF8A28409C56A@PN4P287MB4381.INDP287.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hi ,
Yes, i agree with the statement below , a column is updatable if it is a simple reference to an updatable column of the underlying base relation . View updatability for composite types (being derived construct) will pose challenges

Possible temporary work around is:

1.
Avoid composite types in views and use individual columns from base table
2.
using a trigger function to update the view for some use cases

        Caution: This email was sent from an external source. Please verify the sender’s identity before clicking links or opening attachments.
While simple views are automatically updatable [1], this does not extend to composite types; that is, if a view constructs a composite type for one or more columns, this column then is not updatable:

> A column is updatable if it is a simple reference to an updatable column of the underlying base relation

It would seem simple enough to support composite types if the view column is constructed using row expression in which each field is "a simple reference to an updatable column".

As a practical example, this could enable geometric types being exposed at the view layer, but supported in an underlying table by primitive types.

[1] https://www.postgresql.org/docs/current/sql-createview.html#SQL-CREATEVIEW-UPDATABLE-VIEWS

Thanks

Dinesh Nair

________________________________
From: Malthe <mborch(at)gmail(dot)com>
Sent: Wednesday, July 16, 2025 5:36 PM
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Composite types for updatable views

You don't often get email from mborch(at)gmail(dot)com(dot) Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Caution: This email was sent from an external source. Please verify the sender’s identity before clicking links or opening attachments.
While simple views are automatically updatable [1], this does not extend to composite types; that is, if a view constructs a composite type for one or more columns, this column then is not updatable:

> A column is updatable if it is a simple reference to an updatable column of the underlying base relation

It would seem simple enough to support composite types if the view column is constructed using row expression in which each field is "a simple reference to an updatable column".

As a practical example, this could enable geometric types being exposed at the view layer, but supported in an underlying table by primitive types.

[1] https://www.postgresql.org/docs/current/sql-createview.html#SQL-CREATEVIEW-UPDATABLE-VIEWS

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-07-16 20:46:46 Re: index prefetching
Previous Message Andres Freund 2025-07-16 19:39:58 Re: index prefetching