Re: Rule problem: return value of insert - Mailing list pgsql-general

From Tom Lane
Subject Re: Rule problem: return value of insert
Date
Msg-id 20904.1137528147@sss.pgh.pa.us
Whole thread Raw
In response to Rule problem: return value of insert  (Stephen Friedrich <stephen.friedrich@fortis-it.de>)
Responses Re: Rule problem: return value of insert  (Stephen Friedrich <stephen.friedrich@fortis-it.de>)
List pgsql-general
Stephen Friedrich <stephen.friedrich@fortis-it.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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: mac os x compile failure
Next
From: Stephen Friedrich
Date:
Subject: Re: Rule problem: return value of insert