Skip to content
Advertisement

How to do a batch commit in plpgsql?

When I do the below function, some errors occurs:

Here is my sample code.

So could anyone give me a sample of how to finish my job as the above code?

I’m using PostgreSQL 9.2.

Advertisement

Answer

In general, I think there are three approaches you can take:

  • Do without. Just let the whole thing be committed at once, like PostgreSQL wants.
  • Write a wrapper in application code that sets up a transaction and calls your function. (This is simple to do in a shell script, for example.)
  • Use a hack. One hack that exists is, you can have your function create a database-link to your own database, and perform subtransactions via remote sessions. [More information.] (This is essentially equivalent to the “wrapper in application code” approach, except that the application code is still in PL/pgSQL.)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement