By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

Rule problem

P: n/a


Hello all



I tried to use following rule instead of using a default value(I want to be
able to put a function instead of the constant value later on). But it keeps
giving me infinite recursion error. Any ideas?



CREATE OR REPLACE RULE "INSERT" AS

ON INSERT TO customer_rate where new.code is null DO INSTEAD INSERT INTO
customer_rate (prefix, rate, name, code,groupid)

VALUES (new.prefix, new.rate, new.name,'1',new.groupid);



Thanking you in advance

Regards

Kia


Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Kiarash Bodouhi" <kb******@yahoo.com> writes:
I tried to use following rule instead of using a default value
You can't ... at least not that way.
(I want to be
able to put a function instead of the constant value later on).


There's nothing stopping you from putting a function into the DEFAULT
clause.

A "BEFORE INSERT" trigger is another possible approach.

Novices often think that rules are simpler to use than triggers,
but in my experience the opposite is true. Triggers have some
notational ugliness but the conceptual model is simple ... for
rules the notation looks easy but wrapping your head around what
will really happen is another story.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #2

P: n/a
Thanks for the reply. I initially wanted to put the function as the default
clause. But the problem is that the function should receive one of the other
fields as the argument. Is there anyway to do that? I guess as you said I
have to use triggers.

-----Original Message-----
From: Tom Lane [mailto:tg*@sss.pgh.pa.us]
Sent: Sunday, October 10, 2004 4:53 PM
To: Kiarash Bodouhi
Cc: pg***********@postgresql.org
Subject: Re: [GENERAL] Rule problem

"Kiarash Bodouhi" <kb******@yahoo.com> writes:
I tried to use following rule instead of using a default value
You can't ... at least not that way.
(I want to be
able to put a function instead of the constant value later on).


There's nothing stopping you from putting a function into the DEFAULT
clause.

A "BEFORE INSERT" trigger is another possible approach.

Novices often think that rules are simpler to use than triggers,
but in my experience the opposite is true. Triggers have some
notational ugliness but the conceptual model is simple ... for
rules the notation looks easy but wrapping your head around what
will really happen is another story.

regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.