From: | Adrian Klaver <aklaver(at)comcast(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org, <andy(at)areyoulocal(dot)co(dot)uk> |
Cc: | "'Andreas Kretschmer'" <akretschmer(at)spamfence(dot)net> |
Subject: | Re: Is it possible to redirect an update/insert/delete to a different table? |
Date: | 2005-11-20 23:35:57 |
Message-ID: | 200511201535.57300.aklaver@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Sunday 20 November 2005 09:15 am, Andy Ballingall wrote:
It works because of the way updates are done. When you do an update two
versions of the row exist. The OLD version is the row as it existed before
you updated. The NEW version contains the entire version with the update
changes. The key thing to remember is the the NEW version contains both those
fields that have changed as well as those that have not. So the UPDATE rule
just passes along all the fields named in it regardless of whether they
changed or not. It would be a good idea to read the following section of the
manual (http://www.postgresql.org/docs/8.0/interactive/rules.html) as it
explains when the rule picks up the values in the fields. This differs
according to the type of rule.
> >Try it. [snipped example]
>
> Ah. Basically, you set up the rule to assign every column, and if the
> update doesn't redefine some columns, then it still works. I didn't
> understand that you could get the rule to work generically like this.
>
> I'll presume that the rule will need amending if the table column
> definition later changes. (E.g. if I add 'stalk_length' to my apples and
> pears tables)...
>
> Thanks very much for your help.
>
> Andy
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
--
Adrian Klaver
aklaver(at)comcast(dot)net
From | Date | Subject | |
---|---|---|---|
Next Message | Hélder M. Vieira | 2005-11-21 12:47:40 | max() unexpected type conversion |
Previous Message | Grigory O. Ptashko | 2005-11-20 19:32:09 | Please help to wite the constraint. |