GET DIAGNOSTICS ROW_COUNT with parallel operations

I would like to use GET DIAGNOSTICS integer_var = ROW_COUNT

plpgsql in code to get the number of rows inserted into a table by a statement INSERT INTO

.

If I run multiple statements INSERT INTO

almost simultaneously, can I be sure that I GET DIAGNOSTICS

correctly return the number of rows inserted for each statement?

I can illustrate this with an example if it happens in the following sequence:

  • User A triggers an insert into statement, which inserts 10 rows into the table.
  • user B triggers insert into statement, which inserts 5 rows into the table.
  • User A calls GET DIAGNOSTICS rowcount = ROW_COUNT;

  • User B calls GET DIAGNOSTICS rowcount = ROW_COUNT;

Will user A get rowcount

out of 10 and user B out of 5? Or will both get 5?

+3


source to share


1 answer


PostgreSQL statement PLpgSQL GET DIAGNOSTICS

shows information about the last statement of a transaction (inside a transaction you are isolated from other users). Thus, users A will see 10 and user B will see 5.



PostgreSQL is ACID and users are highly isolated (usually). In one session, you won't be able to see much of the work of other users. Maximum possible to see the recorded data changes.

+3


source







All Articles