Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
"Creager, Robert S" <[EMAIL PROTECTED]> writes: > You indicate trigger, rather than rule. Going by Momjian's book, he > indicates that rules are "...ideal for when the action affects other > tables." Can you clarify why you would use a trigger for this? Primarily because there's a need to get a

RE: [SQL] Rule/currval() issue

2001-03-14 Thread Creager, Robert S
due > Cc: [EMAIL PROTECTED] > Subject: Re: [SQL] Rule/currval() issue > > > Tim Perdue <[EMAIL PROTECTED]> writes: > > This is related to the plpgsql project I was working on > this morning. I'm > > trying to create a rule, so that when a row is inser

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
Tim Perdue <[EMAIL PROTECTED]> writes: >> You probably should be using a trigger, not a rule at all. > OK - so another rule like this one, is probably ill-advised as well? It seems > a lot easier than going into the triggers: > CREATE RULE forum_delete_agg AS > ON DELETE TO forum > DO UP

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tim Perdue
On Wed, Mar 14, 2001 at 01:09:18PM -0500, Tom Lane wrote: > Tim Perdue <[EMAIL PROTECTED]> writes: > > This is related to the plpgsql project I was working on this morning. I'm > > trying to create a rule, so that when a row is inserted into a certain table, > > we also create a row over in a "cou

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Tom Lane
Tim Perdue <[EMAIL PROTECTED]> writes: > This is related to the plpgsql project I was working on this morning. I'm > trying to create a rule, so that when a row is inserted into a certain table, > we also create a row over in a "counter table". The problem lies in getting > the primary key value (

Re: [SQL] Rule/currval() issue

2001-03-14 Thread Andrew Perrin
Entirely untested, but how about replacing currval() in your first try with nextval()? My theory is that the compilation of the function is happening before the INSERT happens; therefore the sequence hasn't been incremented yet; therefore there's no currval() for this backend instance. If you use

[SQL] Rule/currval() issue

2001-03-14 Thread Tim Perdue
This is related to the plpgsql project I was working on this morning. I'm trying to create a rule, so that when a row is inserted into a certain table, we also create a row over in a "counter table". The problem lies in getting the primary key value (from the sequence) so it can be inserted in tha