| From: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> | 
|---|---|
| To: | pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: is it a bug in rule system? | 
| Date: | 2008-05-28 08:28:25 | 
| Message-ID: | 20080528082825.GA25117@a-kretschmer.de | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
am  Wed, dem 28.05.2008, um 15:56:22 +0800 mailte laser folgendes:
> hi all,
> 
> see query below:
> 
> create table ruleTest(id integer, name text);
> 
> create or replace rule ruleTest_insert_rule AS on insert to ruleTest
> where exists(select 1 from ruleTest where ruleTest.name = NEW.name)
> do instead (update ruleTest set id = id+1 where ruleTest.name = NEW.name);
>
> I think the id should be 1, cause the rule condition should only affect 
> exist row,
> but ISTM the rule act like a DO ALSO rule: insert the row first, then 
> update it.
> 
> any hints?
Yes, use a TRIGGER instead a RULE for such tasks.
Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kaloyan Iliev | 2008-05-28 08:30:46 | Re: Open Source CRM - Options? | 
| Previous Message | laser | 2008-05-28 07:56:22 | is it a bug in rule system? |