Why can I reliably create/drop temporary tables in PL/PgSQL functions?
PL/PgSQL caches function contents, and an unfortunate side effect is that if a PL/PgSQL function accesses a temporary table, and that table is later dropped and recreated, and the function called again, the function will fail because the cached function contents still point to the old temporary table. The solution is to use EXECUTE for temporary table access in PL/PgSQL. This will cause the query to be reparsed every time.
Related Questions
- Why do I get "relation with OID ##### > does not exist" errors when accessing temporary tables in PL/PgSQL > functions?
- One possible re-phrasing would be: "Why do temporary tables in PL/PgSQL functions give me "missing oid" errors?
- Why can I reliably create/drop temporary tables in PL/PgSQL functions?