Updatable View (Was: Separating data sets in a table)

From: Andreas Tille <tillea(at)rki(dot)de>
To: PostgreSQL SQL <pgsql-sql(at)postgresql(dot)org>
Subject: Updatable View (Was: Separating data sets in a table)
Date: 2002-08-23 10:00:12
Message-ID: Pine.LNX.4.44.0208231153340.1478-100000@wr-linux02.rki.ivbb.bund.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 22 Aug 2002, Andreas Tille wrote:

> I want to solve the following problem:
>
> CREATE TABLE Ref ( Id int ) ;
> CREATE TABLE Import ( Id int,
> Other varchar(42),
> Flag int,
> Ts timestamp ) ;
> CREATE TABLE Data ( Id int,
> Other varchar(42) ) ;
>
> The table Import will be filled by a COPY FROM statement and contains
> no checks for referential integrity. The columns Id and Other have to
> be moved to the table Data if the table Ref contains the Id. If not
> Flag should get a certain value that something went wrong. Moreover
> Import should only contain one representation of a dataset with equal
> Id and Other column and I would like to store the newest one (this
> is the reason for the timestamp).
> ...
While I fiddled around with my previous solution I found out that perhaps
an updatable view could solve my problem. Thus I tried to implement:

CREATE TABLE ViewImport ( Id int,
Other varchar(42),
Flag int,
Ts timestamp ) ;
CREATE RULE "_RETviewimport" AS
ON SELECT TO ViewImport
DO INSTEAD
SELECT i.* FROM Import i
INNER JOIN Ref r ON i.Id = r.Id;

Now I wonder if it is possible to find a clever rule for update which
contains the JOIN I placed into this working example to set the Flag
just right now for the appropriate data sets.

Any help for this approach or any other solution for this problem?

Kind regards

Andreas.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-08-23 13:25:44 Re: SELECT ... WHERE ... NOT IN (SELECT ...);
Previous Message Richard Huxton 2002-08-23 09:24:28 Re: SELECT ... WHERE ... NOT IN (SELECT ...);