Re: [GENERAL] Rule Question

2013-07-25 Thread Sergey Konoplev
On Wed, Jul 24, 2013 at 11:44 PM, Andrew Bartley ambart...@gmail.com wrote: Hope this question is not too stupid but.. I am trying to do something like this create table cats (a text,b text); create rule cats_test as on update to cats do set a = new.b; Can i manipulate column a sort

Re: [GENERAL] Rule Question

2013-07-25 Thread Luca Ferrari
On Thu, Jul 25, 2013 at 8:44 AM, Andrew Bartley ambart...@gmail.com wrote: create rule cats_test as on update to cats do set a = new.b; I would use a column trigger attached to the 'a' column. Rules are better for query rewriting rather than from semantic changes. That's my opinion. Luca --

Re: [GENERAL] Rule Question

2013-07-25 Thread Giuseppe Broccolo
I am trying to do something like this create table cats (a text,b text); create rule cats_test as on update to cats do set a = new.b; Can i manipulate column a sort of like this... or is there a better way. I think the easiest way to do this is to use a trigger like this: CREATE

Re: [GENERAL] Rule Question

2013-07-25 Thread Luca Ferrari
The original post was related to the update of b, so I guess it is better to limit the trigger scope to update on such column: CREATE OR REPLACE FUNCTION b_mirror() RETURNS TRIGGER AS $mirror$ BEGIN NEW.a = NEW.b; RETURN NEW; END; $mirror$ LANGUAGE plpgsql; CREATE TRIGGER tr_b_mirror AFTER

Re: [GENERAL] Rule Question

2013-07-25 Thread Tom Lane
Luca Ferrari fluca1...@infinito.it writes: The original post was related to the update of b, so I guess it is better to limit the trigger scope to update on such column: CREATE OR REPLACE FUNCTION b_mirror() RETURNS TRIGGER AS $mirror$ BEGIN NEW.a = NEW.b; RETURN NEW; END; $mirror$

Re: [GENERAL] Rule Question

2013-07-25 Thread Luca Ferrari
On Thu, Jul 25, 2013 at 3:02 PM, Tom Lane t...@sss.pgh.pa.us wrote: Luca Ferrari fluca1...@infinito.it writes: The original post was related to the update of b, so I guess it is better to limit the trigger scope to update on such column: CREATE OR REPLACE FUNCTION b_mirror() RETURNS TRIGGER

Re: [GENERAL] Rule Question

2013-07-25 Thread bricklen
On Thu, Jul 25, 2013 at 4:18 AM, Giuseppe Broccolo giuseppe.brocc...@2ndquadrant.it wrote: (TG_OP = 'UPDATE' AND (NEW.b != OLD.b OR (NEW.b IS NULL AND OLD.b IS NOT NULL) OR (NEW.b IS NOT NULL AND OLD.b IS NULL)

Re: [GENERAL] Rule Question

2013-07-25 Thread Giuseppe Broccolo
Unrelated to the OP's question, the suggestion above could be more simply rewritten as TG_OP = 'UPDATE' AND NEW.b IS DISTINCT FROM OLD.b You're right! :) Giuseppe. -- Giuseppe Broccolo - 2ndQuadrant Italy PostgreSQL Training, Services and Support giuseppe.brocc...@2ndquadrant.it |

Re: [GENERAL] Rule Question

2013-07-25 Thread Andrew Bartley
Thanks All, And thanks Tom, I did not realise a rule worked in that manner. Will now take that into account in the future. Thanks Andrew On 26 July 2013 02:02, Giuseppe Broccolo giuseppe.brocc...@2ndquadrant.itwrote: Unrelated to the OP's question, the suggestion above could be more

Re: [GENERAL] rule question

2008-02-29 Thread Tim Rupp
Klint Gore wrote: [see below or the top posting police will arrive on my doorstep :)] Devi wrote: Hi, CREATE RULE dosen't require any lock. It is carried out in the parser level. But there will be ACCESS SHARE lock over the tables which are being queried are acquired automatically.

Re: [GENERAL] rule question

2008-02-29 Thread Scott Marlowe
On Fri, Feb 29, 2008 at 4:08 AM, Tim Rupp [EMAIL PROTECTED] wrote: One other question. If the lock needed is exclusive, and more inserts come in after it is requested, will Postgres schedule the rule to be created before those new inserts are allowed to happen? Or can the rule request sit

Re: [GENERAL] rule question

2008-02-28 Thread Devi
Hi, CREATE RULE dosen't require any lock. It is carried out in the parser level. But there will be ACCESS SHARE lock over the tables which are being queried are acquired automatically. Thanks DEVI.G - Original Message - From: Tim Rupp [EMAIL PROTECTED] To:

Re: [GENERAL] rule question

2008-02-28 Thread Klint Gore
[see below or the top posting police will arrive on my doorstep :)] Devi wrote: Hi, CREATE RULE dosen't require any lock. It is carried out in the parser level. But there will be ACCESS SHARE lock over the tables which are being queried are acquired automatically. Thanks DEVI.G -