Thread: Catching "UPDATE 0"

Catching "UPDATE 0"

From
Date:
Hello,
I am trying to catch the "UPDATE 0" condition in postgresql.
I have tried it using triggers, but they are only fired when there
effectively is an update. So, an Update 0 does not fire triggers.
Is it possible to make the backend raise and exception when the
Update 0 happens? This would be useful for knowing when records
were not updated as those which are in concurrent transactions.
By the way, How do I know if a transaction was really committed
and not rollbacked?


Re: Catching "UPDATE 0"

From
Neil Conway
Date:
<enio@pmpf.rs.gov.br> writes:
> I am trying to catch the "UPDATE 0" condition in postgresql.
> I have tried it using triggers, but they are only fired when there
> effectively is an update.

You could try using an AFTER STATEMENT trigger (which will be invoked
even if zero rows are updated), and checking the size of the set of
modified rows ... except that we currently don't provide a way for
per-statement triggers to access the set of modified tuples.

If someone implements that functionality (which is on the TODO list),
that would be a clean solution to your problem.

-Neil