Jaymes
Jaymes

Reputation: 33

Updating a view column in Postgresql

So, I have a database of customers information ranging from phone numbers to names and even location.

I created a view of only the active customers and included an extra blank column where we can indicate if the customer has made purchase or not.

The issue now is, i keep getting an error: cannot update column "buy" of view

I tried entering a value in the blank column created.

Please how can I update a blank column in view

Upvotes: 0

Views: 41

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 246268

If you have a view column defined like

NULL::text AS viewvol

or

''::text AS viewcol

you cannot insert values into that column, nor can you update it. Data modifications on a view are translated to data modifications on the base table, and that only works for view columns that are defined using table columns.

What you can and should do is to create an INSTEAD OF UPDATE trigger for the view that performs the desired operation on the base table.

Upvotes: 2

Related Questions