Commit 6918df16 authored by Tom Lane's avatar Tom Lane

plpgsql's PERFORM statement now sets FOUND depending on whether any

rows were returned by the performed query.  Per recent pgsql-general
discussion.
parent e11f1677
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.59 2002/06/15 19:34:51 momjian Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.60 2002/06/24 23:12:06 tgl Exp $
--> -->
<chapter id="plpgsql"> <chapter id="plpgsql">
...@@ -903,7 +903,9 @@ PERFORM <replaceable>query</replaceable>; ...@@ -903,7 +903,9 @@ PERFORM <replaceable>query</replaceable>;
This executes a <literal>SELECT</literal> This executes a <literal>SELECT</literal>
<replaceable>query</replaceable> and discards the <replaceable>query</replaceable> and discards the
result. <application>PL/pgSQL</application> variables are substituted result. <application>PL/pgSQL</application> 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.
</para> </para>
<note> <note>
...@@ -916,11 +918,7 @@ PERFORM <replaceable>query</replaceable>; ...@@ -916,11 +918,7 @@ PERFORM <replaceable>query</replaceable>;
<para> <para>
An example: An example:
<programlisting> <programlisting>
PERFORM create_mv(''cs_session_page_requests_mv'','' PERFORM create_mv(''cs_session_page_requests_mv'', my_query);
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 '');
</programlisting> </programlisting>
</para> </para>
</sect2> </sect2>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* procedural language * procedural language
* *
* IDENTIFICATION * 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. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -969,9 +969,11 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt) ...@@ -969,9 +969,11 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt)
else else
{ {
/* /*
* PERFORM: evaluate query and discard result. This cannot share * PERFORM: evaluate query and discard result (but set FOUND
* code with the assignment case since we do not wish to * depending on whether at least one row was returned).
* constraint the discarded result to be only one row/column. *
* 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; int rc;
...@@ -985,6 +987,8 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt) ...@@ -985,6 +987,8 @@ exec_stmt_assign(PLpgSQL_execstate * estate, PLpgSQL_stmt_assign * stmt)
if (rc != SPI_OK_SELECT) if (rc != SPI_OK_SELECT)
elog(ERROR, "query \"%s\" didn't return data", expr->query); elog(ERROR, "query \"%s\" didn't return data", expr->query);
exec_set_found(estate, (estate->eval_processed != 0));
exec_eval_cleanup(estate); exec_eval_cleanup(estate);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment