X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id F35D73A3EAA for ; Tue, 2 Nov 2004 15:42:40 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86375-09 for ; Tue, 2 Nov 2004 15:42:35 +0000 (GMT) Received: from mail.logi-track.com (www.logi-track.com [213.239.193.212]) by svr1.postgresql.org (Postfix) with ESMTP id 334123A3E91 for ; Tue, 2 Nov 2004 15:42:38 +0000 (GMT) Received: from kingfisher.intern.logi-track.com (J2582.j.pppool.de [85.74.37.130]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logi-track.com (Postfix) with ESMTP id 7481B30016; Tue, 2 Nov 2004 16:42:42 +0100 (CET) Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) by kingfisher.intern.logi-track.com (Postfix) with SMTP id 3E043AB340; Tue, 2 Nov 2004 16:42:37 +0100 (CET) Date: Tue, 2 Nov 2004 16:42:36 +0100 From: Markus Schaber To: PostgreSQL SQL Subject: Re: Update instead rules on Views Message-ID: <20041102164236.639f10c9@kingfisher.intern.logi-track.com> In-Reply-To: <20041102162037.306d4d0a@kingfisher.intern.logi-track.com> References: <20041102130507.2acf486a@kingfisher.intern.logi-track.com> <20041102162037.306d4d0a@kingfisher.intern.logi-track.com> Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= X-Mailer: Sylpheed-Claws 0.9.12b (GTK+ 1.2.10; i386-pc-linux-gnu) X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: > > -- But to remain compatibility with old apps, we also need to manage > > -- updates to the view, which are to be rewritten as follows: > > CREATE RULE testview_update_rule=20 > > AS ON UPDATE TO testview DO INSTEAD=20 > > UPDATE realdata SET=20 > > index =3D NEW.index, > > data =3D NEW.data, > > obsolete=3DNULL > > ; >=20 > I now got it to work with adding a "WHERE index=3DNEW.index" to the view. This seems only to work when I update on the INDEX row. I now modified the rule to look like: CREATE RULE testview_update_rule=20 AS ON UPDATE TO testview DO INSTEAD=20 UPDATE realdata SET=20 index =3D NEW.index, data =3D NEW.data, obsolete=3DNULL WHERE index =3D OLD.index; This seems to work now for arbitrary columns, provided that index is an unique row. When I have a table that looks like index | data | obsolete=20 -------+-------+---------- 2 | test | =20 3 | blubb | =20 1 | nono | =20 3 | hallo | =20 and I issue =20 viewtest=3D# update testview set data=3D'blob' where data=3D'hallo'; I get: UPDATE 2 and it really updated 2 rows. As far as I understand now, I need a primary key in the underyling table as the qualification from the original statemet is applied to the view results, and not propagated to the underlying table. Thanks, Markus --=20 markus schaber | dipl. informatiker logi-track ag | rennweg 14-16 | ch 8001 z=FCrich phone +41-43-888 62 52 | fax +41-43-888 62 53 mailto:schabios@logi-track.com | www.logi-track.com