we're having a similar situation, where FunctionA calls FunctionB inside a cursor. FunctionB DROPs Temp table, then creates temp table. FunctionA runs through the cursor fine but breaks after the last loop, unable to DROP temporary table "because it is being used by active queries in this session." Those sessions should have been closed after each loop! Here is my ticket on this: http://postgresql.1045698.n5.nabble.com/Can-t-drop-temp-table-in-subfunction-during-cursor-loop-being-used-by-active-queries-td4482806.html#a4484134 Here is another similar (and unanswered) ticket: http://forums.enterprisedb.com/posts/list/849.page -- View this message in context: http://postgresql.1045698.n5.nabble.com/temp-tables-not-dropping-at-end-of-script-tp4286391p4484759.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general