Writing a generic delete rule for a view

From: Scott Cain <scott(at)scottcain(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Writing a generic delete rule for a view
Date: 2009-03-05 18:20:50
Message-ID: 536f21b00903051020n5c7340c2ve96e0977365839f7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

I have a relatively straight forward set up with two schemas, the main
public schema and a private schema (called "testschema" here). The
tables in both schemas are nearly identical: for each table "foo" in
the public schema, there is a table "testschema._foo" and a view
"testschema.foo" in the private schema, where testschema.foo is a
simple union of the public and private tables, to make it appear when
querying in the private schema that the tables are exactly the same as
the public schema, and that the tables have a union of what is in the
private and public schemas.

Now, I would like to allow insert, update and delete rules on the
private views to do the same actions in private tables (that is, an
insert into testschema.foo should really do an insert into
testschema._foo). Writing rules to do the update and inserts was
fairly straight forward. What I don't understand how to do is a
general rule for doing deletes on testschema._foo. What I would like
would be a way to "grab" the where clause and append it onto the DO
INSTEAD for the rule. I'm thinking something like this:

CREATE OR REPLACE RULE testschema_delete_foo
AS ON DELETE TO testschema.foo
DO INSTEAD (DELETE FROM testschema._foo WHERE $where);

So, what I want to know is, is there a "magic" way to get that $where?

Thanks,
Scott

--
------------------------------------------------------------------------
Scott Cain, Ph. D. scott at scottcain dot net
GMOD Coordinator (http://gmod.org/) 216-392-3087
Ontario Institute for Cancer Research

Browse pgsql-sql by date

  From Date Subject
Next Message Oliveiros Cristina 2009-03-05 18:25:38 Re: uso de dblink en php
Previous Message Jhonny Velasquez c. 2009-03-05 15:50:56 uso de dblink en php