Re: Rules on a view overwrite default values. Any way to

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Bradley Kieser <brad(at)kieser(dot)net>
Cc: PgSQL ADMIN <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Rules on a view overwrite default values. Any way to
Date: 2005-01-03 17:30:59
Message-ID: 20050103092722.M55197@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Mon, 3 Jan 2005, Bradley Kieser wrote:

> Hi,
>
> I use views extensively to implement security on tables. This requires
> each table to have a view. All updates, inserts and deletes take place
> through the view. The view has rules for each of these operations
> defining security for that table. Under other conditions, the view also
> removes complex views of the underlying data from the application layer
> by supplying a view where the rules for update, insert and delete
> implement business logic.
>
> The problem is that rules on a view mean that the default values for NOT
> NULL columns (used extensively) no longer trigger!
>
> E.g.
>
> Table A had column "updated_time" which is not null default now().
> Inserting into the view on table A where "updated_time" has not been
> supplied will not fill in "now()". It will attempt to put in a null
> value and hence the insert will fail in the insert rule on that view.

I believe the easiest way is to attach a default to the view column
using ALTER TABLE viewname ALTER COLUMN viewcolumn SET DEFAULT
defaultexpr.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2005-01-03 17:32:18 Re: Rules on a view overwrite default values. Any way to reinstate them?
Previous Message Bradley Kieser 2005-01-03 17:24:32 Re: Rules on a view overwrite default values. Any way to