From: | Roger Pack <rogerdpack2(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | ability to return number of rows inserted into child partition tables request |
Date: | 2014-09-30 21:17:52 |
Message-ID: | CAL1QdWdAq44onx=Vcvz0GSZf668jokZt2hs-S+0wrLpkvrCA3Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
Hello.
I was trying to get postgres to return the "correct" number of rows
inserted for batch inserts to a partitioned table [using the triggers as
suggested here
http://www.postgresql.org/docs/9.1/static/ddl-partitioning.html results in
it always returning 0 by default].
What I ideally wanted it to do is to be able to insert into just the child
partitions, and return number of rows updated.
It seems the state of the art is either to return the NEW row from the
insert trigger [which causes it to also be saved to the parent master
table], then define an extra trigger to remove the parent table. So 2
inserts and 1 delete for an insert. [1]
Or you can use an unconditional rule and it will return the number of rows
updated [however, in this case, since we're using partitioning, we I think
need multiple rules, once for each child table].
It is possible for a view to use a trigger and still return the number of
rows updated, which provides another work around. (See bottom of [1]).
Is there some more elegant way here? It seems odd that partitioned tables
basically cannot, without a *lot* of massaging, return number of rows
updated, am I missing something or do I understand ok? [Today this requires
people to put in lots of work arounds, like *not* checking for number of
rows returned for batch inserts, etc.-- potentially dangerous as well]
Is there, for instance, some work around, like a way to manually cause the
count of the number of rows affected by the command to be incremented
here? Or possibly conditional rules could be made possible to return the
output string with number of rows affected (feature request)?
I guess this has come up before, FWIW.
http://grokbase.com/t/postgresql/pgsql-general/0863bjzths/insert-into-master-table-0-rows-affected-hibernate-problems
Thanks!
-roger-
[1]
http://stackoverflow.com/questions/83093/hibernate-insert-batch-with-partitioned-postgresql
PS if no response I'll forward this on to pghackers.
From | Date | Subject | |
---|---|---|---|
Next Message | Jonathan Vanasco | 2014-09-30 23:50:20 | improving speed of query that uses a multi-column "filter" ? |
Previous Message | Dev Kumkar | 2014-09-30 19:32:04 | Re: [SQL] pg_multixact issues |
From | Date | Subject | |
---|---|---|---|
Next Message | Fabrízio de Royes Mello | 2014-09-30 21:20:01 | CREATE IF NOT EXISTS INDEX |
Previous Message | Andres Freund | 2014-09-30 21:15:33 | Re: INSERT ... ON CONFLICT {UPDATE | IGNORE} |