Chapman Flack <c...@anastigmatix.net> writes: > I probably just need to learn the right coding pattern for this. > What is it?
You can't just ignore a thrown error like that. What you'd have to do to make this coding pattern work is to set up a subtransaction, and either commit it in the success path or roll it back upon catching an error. (This is not terribly well documented, but the exception-block handling in plpgsql provides a working model to follow.) Without subtransaction cleanup, lots of stuff will be left in incorrect states --- the unbalanced SPI stack you're seeing is just the tip of the iceberg. 99% of the time, the path of least resistance at the C-code level is to avoid expected error conditions in the first place, rather than try to catch and clean up. In this example, there are plenty of ways you might test whether "mytable" exists before risking the SPI_execute call. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers