Add item for plpgsql temp table access.
authorBruce Momjian
Mon, 10 Jun 2002 19:47:57 +0000 (19:47 +0000)
committerBruce Momjian
Mon, 10 Jun 2002 19:47:57 +0000 (19:47 +0000)
doc/FAQ
doc/src/FAQ/FAQ.html

diff --git a/doc/FAQ b/doc/FAQ
index 2c4193a833d53f00823e4312155b78d3c7390760..c88898194959e15768347cb923dfa61206136f12 100644 (file)
--- a/doc/FAQ
+++ b/doc/FAQ
@@ -1,7 +1,7 @@
 
                 Frequently Asked Questions (FAQ) for PostgreSQL
                                        
-   Last updated: Fri Apr 26 23:03:46 EDT 2002
+   Last updated: Mon Jun 10 15:47:38 EDT 2002
    
    Current maintainer: Bruce Momjian ([email protected])
    
@@ -92,6 +92,8 @@
    4.23) How do I perform an outer join?
    4.24) How do I perform queries using multiple databases?
    4.25) How do I return multiple rows or columns from a function?
+   4.26) Why can't I reliably create/drop temporary tables in PL/PgSQL
+   functions?
    
                             Extending PostgreSQL
                                       
@@ -1031,6 +1033,17 @@ SELECT *
    http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html,
    section 23.7.3.3.
    
+    4.26) Why can't 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.
+   
                             Extending PostgreSQL
                                       
     5.1) I wrote a user-defined function. When I run it in psql, why does it
index 988aa3f968f7ca070b6460cc854636afd8641d5b..8ca6cd9c454e56cfe13166302a1419c60c577b96 100644 (file)
@@ -14,7 +14,7 @@
   alink="#0000ff">
     

Frequently Asked Questions (FAQ) for PostgreSQL

 
-    

Last updated: Fri Apr 26 23:03:46 EDT 2002

+    

Last updated: Mon Jun 10 15:47:38 EDT 2002

 
     

Current maintainer: Bruce Momjian (

      4.24) How do I perform queries using multiple
     databases?
      4.25) How do I return multiple rows or columns
-     from a function?
+    from a function?
+     4.26) Why can't I reliably create/drop
+    temporary tables in PL/PgSQL functions?
      
 
     Extending PostgreSQL
     

You can also compile with profiling to see what functions are

     taking execution time. The backend profile files will be deposited
     in the pgsql/data/base/dbname directory. The client profile
-    file will be put in the client's current directory.  Linux requires
+    file will be put in the client's current directory. Linux requires
     a compile with -DLINUX_PROFILE for proper profiling.

 
     

3.8) Why do I get "Sorry, too many

     databases, and users are defined?
 
     

psql has a variety of backslash commands to show such

-    information. Use \? to see them.  There are also system tables
-    beginning with <i>pg_ that describe these too.  Also, >psql
-    -li> will list all databases.

+    information. Use \? to see them. There are also system tables
+    beginning with <I>pg_ that describe these too. Also, >psql
+    -lI> will list all databases.

 
     

Also try the file pgsql/src/tutorial/syscat.source. It

     illustrates many of the SELECTs needed to get
@@ -1307,16 +1309,25 @@ BYTEA           bytea           variable-length byte array (null-byte safe)
     different databases and merge the information that way.

     
 
-    

4.25) How do I return multiple rows or columns

-     from a function?
+    

4.25) How do I return multiple rows or

+    columns from a function?
+
+    

You can return result sets from PL/pgSQL functions using

+    refcursors. See 
+    "http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html">
+    http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html,
+    section 23.7.3.3.

+
+    

4.26) Why can't 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. 
 
-     

You can return result sets from PL/pgSQL functions using

-     refcursors. See 
-     href="http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html">
-     http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html,
-     section 23.7.3.3.

-
-     
     Extending PostgreSQL
 
     

5.1) I wrote a user-defined function. When I