pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
question on rules
4+ messages / 4 participants
[nested] [flat]

* question on rules
@ 2003-06-13 01:26  weigelt@metux.de
  0 siblings, 2 replies; 4+ messages in thread

From: weigelt@metux.de @ 2003-06-13 01:26 UTC (permalink / raw)
  To: pgsql-sql


hi folks,

i'd like to write an rule which fills out some empty attrs on 
insert (w/ data from other given attrs).

the table structure is:
CREATE TABLE foo (start date, duration integer, endtime date);

and the rule is:
CREATE RULE foo1 AS ON INSERT TO foo WHERE new.endtime = NULL DO 
    INSERT INTO foo SELECT new.start, new.duration, new.start + new.duration;
    
when i try to insert some data (INSERT INTO foo SELECT '2003-01-01', '12';)
i get the error: query rewritten 10 times, may contain cycles.

how can i avoid this loop ?

cu
-- 
---------------------------------------------------------------------
 Enrico Weigelt    ==   metux ITS 
 Webhosting ab 5 EUR/Monat.          UUCP, rawIP und vieles mehr.

 phone:     +49 36207 519931         www:       http://www.metux.de/     
 fax:       +49 36207 519932         email:     contact@metux.de
 cellphone: +49 174 7066481	     smsgate:   sms.weigelt@metux.de
---------------------------------------------------------------------
 Diese Mail wurde mit UUCP versandt.      http://www.metux.de/uucp/



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: question on rules
@ 2003-06-13 01:57  Tom Lane <tgl@sss.pgh.pa.us>
  parent: weigelt@metux.de
  1 sibling, 1 reply; 4+ messages in thread

From: Tom Lane @ 2003-06-13 01:57 UTC (permalink / raw)
  To: weigelt@metux.de; +Cc: pgsql-sql

weigelt@metux.de writes:
> i'd like to write an rule which fills out some empty attrs on 
> insert (w/ data from other given attrs).

You'd be better off doing this with a BEFORE INSERT trigger.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: question on rules
@ 2003-06-13 06:00  Tomasz Myrta <jasiek@bt.jordan.pl>
  parent: weigelt@metux.de
  1 sibling, 0 replies; 4+ messages in thread

From: Tomasz Myrta @ 2003-06-13 06:00 UTC (permalink / raw)
  To: weigelt@metux.de; +Cc: pgsql-sql

Dnia 2003-06-13 03:26, Uz.ytkownik weigelt@metux.de napisa?:
> hi folks,
> 
> i'd like to write an rule which fills out some empty attrs on 
> insert (w/ data from other given attrs).
> 
> the table structure is:
> CREATE TABLE foo (start date, duration integer, endtime date);
> 
> and the rule is:
> CREATE RULE foo1 AS ON INSERT TO foo WHERE new.endtime = NULL DO 
>     INSERT INTO foo SELECT new.start, new.duration, new.start + new.duration;
>     
> when i try to insert some data (INSERT INTO foo SELECT '2003-01-01', '12';)
> i get the error: query rewritten 10 times, may contain cycles.
> 
> how can i avoid this loop ?
For this case creating trigger would be much better than rule.
I think, you can't use rules this way.

Regards,
Tomasz Myrta





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: question on rules
@ 2003-06-13 16:30  Jan Wieck <JanWieck@Yahoo.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Jan Wieck @ 2003-06-13 16:30 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql

Tom Lane wrote:
> weigelt@metux.de writes:
>> i'd like to write an rule which fills out some empty attrs on 
>> insert (w/ data from other given attrs).
> 
> You'd be better off doing this with a BEFORE INSERT trigger.

The only way to do it with rules would be to create a view over the 
basetable, create an insert rule over the view and then have the 
application doing the insert into the view instead. So "better" could be 
considered an understatement :-)


Jan

-- 
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#================================================== JanWieck@Yahoo.com #




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-06-13 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-13 01:26 question on rules weigelt@metux.de
2003-06-13 01:57 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-06-13 16:30   ` Jan Wieck <JanWieck@Yahoo.com>
2003-06-13 06:00 ` Tomasz Myrta <jasiek@bt.jordan.pl>

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