dbTalk Databases Forums  

Create Rule

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Create Rule in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Luc ROLLAND
 
Posts: n/a

Default Create Rule - 02-17-2004 , 02:01 PM






Hello !

I would use a rule to store in each modified records the name of the user and the date of modification.
I try :

CREATE RULE shoe_mod AS ON UPDATE TO shoe_data
DO INSTEAD UPDATE shoe_data
SET shoename = NEW.shoename,
sh_avail = NEW.sh_avail,
slcolor = NEW.slcolor,
slminlen = NEW.slminlen,
slmaxlen = NEW.slmaxlen,
slunit = NEW.slunit,
shuser = current_user,
shdatmod = current_date
WHERE shoename = OLD.shoename ;

but I obtain an infinite loop ...
How can I do that.

Best regards.

Luc ROLLAND

Reply With Quote
  #2  
Old   
Luc ROLLAND
 
Posts: n/a

Default Re: Create Rule - 02-18-2004 , 07:23 AM






Hi jeremy !

Your solution (creating the rule on a view, then updating the view) works fine !

Thanks.

Reply With Quote
  #3  
Old   
joseph speigle
 
Posts: n/a

Default Re: Create Rule - 02-21-2004 , 04:26 AM



okay, its a novice list so I'll take a crack at this one.

I couldn't find create rule as ... select .... in the documentation, only rules for insert,update,delete.
Using it says ERROR: parser: parse error at or near "*" at character 43
(that;s the * for the select)

I think the problem comes from bastardizing the documentation. You should be doing this on a view, and then updating the real table. It should be "AS ON UPDATE TO shoe_data_view DO INSTEAD UPDATE real_shoe_data_table. The link in the doc is
http://www.sirfsup.com/sql_servers/p...es-update.html
half-way down the page.


On Tue, Feb 17, 2004 at 01:14:15PM -0800, Jeremy Semeiks wrote:
Quote:
On Tue, Feb 17, 2004 at 09:01:51PM +0100, Luc ROLLAND wrote:
Hello !

I would use a rule to store in each modified records the name of the user and the date of modification.
I try :

CREATE RULE shoe_mod AS ON UPDATE TO shoe_data
DO INSTEAD UPDATE shoe_data
SET shoename = NEW.shoename,
sh_avail = NEW.sh_avail,
slcolor = NEW.slcolor,
slminlen = NEW.slminlen,
slmaxlen = NEW.slmaxlen,
slunit = NEW.slunit,
shuser = current_user,
shdatmod = current_date
WHERE shoename = OLD.shoename ;

but I obtain an infinite loop ...
How can I do that.

Hi Luc,

Your rule specifies to update the table, and updating the table
triggers the rule, which specifies to update the table... ad
infinitum.

Try creating the rule on a view instead, then updating the view:

CREATE RULE shoe_data_v AS SELECT * FROM shoe_data;
CREATE RULE shoe_v_mod AS ON UPDATE TO shoe_data_v
DO INSTEAD UPDATE shoe_data
...

HTH,
Jeremy

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly
--
joe speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.