Stephen Friedrich <stephen.friedrich@xxxxxxxxxxxx> 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