Re: Updating a table via a view

From: "Shridhar Daithankar" <shridhar_daithankar(at)persistent(dot)co(dot)in>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Updating a table via a view
Date: 2003-02-10 08:40:44
Message-ID: 3E47B2E4.30756.E51D57D@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > I am trying to maintain a history of rows. The base table has a start
> > and end date. I am updating the table using a view and a rule. The
> > rule, updates the end date on the current record and then inserts a new
> > row with the modified columns, or at least thats what I want to happen.
> >
> > The update is occuring but the insert doesn't. I get no error but no
> > row. The rule looks like this;
> > CREATE RULE a_update
> > AS ON UPDATE TO a DO INSTEAD
> > (UPDATE a_hist
> > SET tend = now()
> > WHERE (a.x = old.x)
> > AND (a.tend = 'infinity'::timestamptz);
> > INSERT INTO a_hist (
> > x,
> > tstart,
> > tend,
> > y,
> > z
> > ) VALUES (
> > new.x,
> > now(),
> > 'infinity'::timestamptz,
> > new.y,
> > new.z
> > );
> > );

I suggest you put all things in a pl/pgsql function and callt that function in
instead rule. It might be that it takes that ';' as end of the SQL command.

HTH

Bye
Shridhar

--
We'll pivot at warp 2 and bring all tubes to bear, Mr. Sulu!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jass 2003-02-10 10:20:00 Maximum size of the primary key
Previous Message ahoward 2003-02-10 08:19:26 Re: Updating a table via a view