plpgsql's PERFORM statement now sets FOUND depending on whether any
authorTom Lane
Mon, 24 Jun 2002 23:12:06 +0000 (23:12 +0000)
committerTom Lane
Mon, 24 Jun 2002 23:12:06 +0000 (23:12 +0000)
rows were returned by the performed query.  Per recent pgsql-general
discussion.

doc/src/sgml/plsql.sgml
src/pl/plpgsql/src/pl_exec.c

index 91e96c77f06a1cc0d98938160b32a6d5d3686e28..082b77fc5b21806418eb955dc28c903719b39d90 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -903,7 +903,9 @@ PERFORM query;
      This executes a SELECT
      query and discards the
      result. PL/pgSQL variables are substituted
-     in the query as usual.
+     in the query as usual.  Also, the special variable FOUND is set to
+     true if the query produced at least one row, or false if it produced
+     no rows.
     
 
     
@@ -916,11 +918,7 @@ PERFORM query;
     
      An example:
 
-PERFORM create_mv(''cs_session_page_requests_mv'',''
-     SELECT   session_id, page_id, count(*) AS n_hits,
-              sum(dwell_time) AS dwell_time, count(dwell_time) AS dwell_count
-     FROM     cs_fact_table
-     GROUP BY session_id, page_id '');
+PERFORM create_mv(''cs_session_page_requests_mv'', my_query);
 
     
    
index ab539dc928a197536138e0f9cbdd7769d6154248..abfce9b8bd2c0d624b2cdea37acba92a8f5534e5 100644 (file)
@@ -3,7 +3,7 @@
  *           procedural language
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.55 2002/03/25 07:41:10 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.56 2002/06/24 23:12:06 tgl Exp $
  *
  *   This software is copyrighted by Jan Wieck - Hamburg.
  *
@@ -969,9 +969,11 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt)
    else
    {
        /*
-        * PERFORM: evaluate query and discard result.  This cannot share
-        * code with the assignment case since we do not wish to
-        * constraint the discarded result to be only one row/column.
+        * PERFORM: evaluate query and discard result (but set FOUND
+        * depending on whether at least one row was returned).
+        *
+        * This cannot share code with the assignment case since we do not
+        * wish to constrain the discarded result to be only one row/column.
         */
        int         rc;
 
@@ -985,6 +987,8 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt)
        if (rc != SPI_OK_SELECT)
            elog(ERROR, "query \"%s\" didn't return data", expr->query);
 
+       exec_set_found(estate, (estate->eval_processed != 0));
+
        exec_eval_cleanup(estate);
    }