Re: Rule problem: return value of insert

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Friedrich <stephen(dot)friedrich(at)fortis-it(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rule problem: return value of insert
Date: 2006-01-17 20:02:27
Message-ID: 20904.1137528147@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephen Friedrich <stephen(dot)friedrich(at)fortis-it(dot)de> writes:
> In fact I have found some related mails in the archive, but I really do not
> understand why '0' is returned.
> The documentation (34.5. Rules and Command Status) says if I replace an INSERT
> with another INSERT the value returned should be from the new INSERT statement?

Not when you're using a pile of conditional rules like that. The last
one to fire determines the result, so you'll only see a nonzero count
when inserting into the last subtable.

I think you'd be better off to forget the rule approach and instead
put a trigger on the parent table that stores the values into the
appropriate subtable and then returns NULL. Unfortunately that won't
fix the rowcount problem either (because suppressed inserts won't be
counted), but it will certainly outperform a large collection of rules.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Friedrich 2006-01-17 20:12:55 Re: Rule problem: return value of insert
Previous Message Tom Lane 2006-01-17 19:56:41 Re: mac os x compile failure