From: | peter pilsl <pilsl(at)goldfisch(dot)at> |
---|---|
To: | PostgreSQL List <pgsql-general(at)postgresql(dot)org> |
Subject: | help with rules please |
Date: | 2006-06-07 11:23:09 |
Message-ID: | 4486B71D.6000102@goldfisch.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I dont succeed with writing my rules proper.
I need the following rules:
when I INSERT/UPDATE to a table and a certain condition is true then a
special field in this data-row should be updated to.
I came as far:
# \d testa
Table "public.testa"
Column | Type | Modifiers
--------+------+-----------
x1 | text |
x2 | text |
Rules:
r1 AS
ON INSERT TO testa
WHERE new.x1 = 'house'::text DO UPDATE testa SET x2 = 'mouse'::text
this works fine. When I insert a row with x1=house then x2 gets set to
mouse.
BUT:
i) it always updates all rows in the tables instead of only the current
row. I guess this is a huge performance-lack on big tables :) I tried
to get a where oid=new.oid in or something like that, but it did not work.
ii) the above rule does not work on UPDATE, cause I get a deep
recursion. Each update causes another update on the same table which
makes postgres break with a nested.loop -error (happily postgres detects
the recursion :)
thnx for any help
peter
--
mag. peter pilsl
goldfisch.at
IT- & dataconsulting
tel: +43 650 3574035
tel: +43 1 8900602
fax: +43 1 8900602 15
pilsl(at)goldfisch(dot)at
From | Date | Subject | |
---|---|---|---|
Next Message | A. Kretschmer | 2006-06-07 11:52:27 | Re: help with rules please |
Previous Message | Jonathon McKitrick | 2006-06-07 10:45:26 | Problem with 'postgres' db with 8.0 on a MacBook |