Discussion:
[ADMIN] How to make the row changes inside trigger function visible to the top level sql statement?
(too old to reply)
haifeng liu
2012-08-06 09:14:34 UTC
Permalink
Hello,

I am doing table partitioning, all is ok except that after executing 'insert' sql statement I can't get affected rows, it always be 0. After searching on the documents, I found that row changes inside trigger function is not visible to the top level statement.

Partition table using a trigger function to redirect insertion to the correct partition is the recommend way, and test affected rows is also used frequently. pgAdmin do test the affected rows too, thus when I type a new row and click save button, it seems failed but actually succeed.

How can I make the row changes inside the trigger function visible to the top level statement?

Thank all in advance!
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Sergey Konoplev
2012-08-09 10:53:54 UTC
Permalink
Post by haifeng liu
Hello,
I am doing table partitioning, all is ok except that after executing 'insert' sql statement I can't get affected rows, it always be 0. After searching on the documents, I found that row changes inside trigger function is not visible to the top level statement.
Partition table using a trigger function to redirect insertion to the correct partition is the recommend way, and test affected rows is also used frequently. pgAdmin do test the affected rows too, thus when I type a new row and click save button, it seems failed but actually succeed.
How can I make the row changes inside the trigger function visible to the top level statement?
It is usually not necessary to check it separately because if there
were no errors than the row has been inserted successfully assuming
your redirecting function is okay. However the only way to get the
inserted row back is to do it from a subsequent statement in the
partitioning case.

In your application you can use LISTEN/NOTIFY if you need to get some
specific information from trigger BTW. May be it will help somehow.
--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: ***@gmail.com Skype: gray-hemp Phone: +79160686204
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Sergey Konoplev
2012-08-09 11:11:45 UTC
Permalink
On Thu, Aug 9, 2012 at 2:53 PM, Sergey Konoplev
Post by Sergey Konoplev
Post by haifeng liu
How can I make the row changes inside the trigger function visible to the top level statement?
your redirecting function is okay. However the only way to get the
inserted row back is to do it from a subsequent statement in the
partitioning case.
BTW I am not completely correct here. There is a solution but it is a
tricky one https://gist.github.com/59067. I am not sure if it is a
good performing one but it will work.
Post by Sergey Konoplev
In your application you can use LISTEN/NOTIFY if you need to get some
specific information from trigger BTW. May be it will help somehow.
--
Sergey Konoplev
a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com
--
Sergey Konoplev

a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com

Jabber: ***@gmail.com Skype: gray-hemp Phone: +79160686204
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Haifeng Liu
2012-08-09 12:32:03 UTC
Permalink
Post by Sergey Konoplev
On Thu, Aug 9, 2012 at 2:53 PM, Sergey Konoplev
Post by Sergey Konoplev
Post by haifeng liu
How can I make the row changes inside the trigger function visible to the top level statement?
your redirecting function is okay. However the only way to get the
inserted row back is to do it from a subsequent statement in the
partitioning case.
BTW I am not completely correct here. There is a solution but it is a
tricky one https://gist.github.com/59067. I am not sure if it is a
good performing one but it will work.
I don't think it's a good solution for a partitioned table. Any how, thank you for the information.
Post by Sergey Konoplev
Post by Sergey Konoplev
In your application you can use LISTEN/NOTIFY if you need to get some
specific information from trigger BTW. May be it will help somehow.
--
Sergey Konoplev
a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com
--
Sergey Konoplev
a database architect, software developer at PostgreSQL-Consulting.com
http://www.postgresql-consulting.com
--
http://www.postgresql.org/mailpref/pgsql-admin
--
Sent via pgsql-admin mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Loading...