pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andy Ballingall <andy@areyoulocal.co.uk>
To: 'Jaime Casanova' <systemguards@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Is it possible to redirect an update/insert/delete to a different table?
Date: Sun, 20 Nov 2005 15:40:41 -0000
Message-ID: <ECOWS02M7sInp0vS0DO0004c584@smtp-out2.blueyonder.co.uk> (raw)
In-Reply-To: <c2d9e70e0511200623w6e90d15bt64a03a2cfcd7132b@mail.gmail.com>

Hello Jaime,

I'm still not quite clear.

Say I have a number of different updates on a table 'apples' in my code,
including:

UPDATE apples set pips=6 and color='yellow' where id=3;
UPDATE apples set size=10 where id=6;

What would a rule look like which, when *any* update is attempted on the
apples table, will instead apply the update to a different table - 'pears'.

I get this far:

CREATE rule pears_instead_of_apples 
	AS ON UPDATE TO apples
	DO INSTEAD UPDATE INTO pears .....;

What do I put where the ..... is, so that the rule will transparently update
the pears table with whatever values happened to be defined by the original
update command? Is there a special keyword that I've missed?

Regards,
Andy Ballingall


-----Original Message-----
From: Jaime Casanova [mailto:systemguards@gmail.com] 
Sent: 20 November 2005 14:23
To: andy@areyoulocal.co.uk
Cc: pgsql-sql@postgresql.org
Subject: Re: Is it possible to redirect an update/insert/delete to a
different table?

> I've looked through rules, and as far as I can make out, they are only
> useful for explicit actions. I'm looking for something that behaves as
> though it simply substitutes the table name for a different table name
> before executing the command, no matter what the command looks like.
>

Make 3 rules (INSERT/UPDATE/DELETE), 4 if you want SELECT as well...

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)



-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date: 20/11/2005





view thread (12+ messages)  latest in thread

Message-ID: <ECOWS02M7sInp0vS0DO0004c584@smtp-out2.blueyonder.co.uk>
Permalink:  ../ECOWS02M7sInp0vS0DO0004c584@smtp-out2.blueyonder.co.uk/
Also on:    postgresql.org/message-id/ECOWS02M7sInp0vS0DO0004c584@smtp-out2.blueyonder.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andy@areyoulocal.co.uk, systemguards@gmail.com
  Subject: Re: Is it possible to redirect an update/insert/delete to a different table?
  In-Reply-To: <ECOWS02M7sInp0vS0DO0004c584@smtp-out2.blueyonder.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox