File tree Expand file tree Collapse file tree 4 files changed +71
-2
lines changed
Expand file tree Collapse file tree 4 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 1- <!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.137 2009/02/04 21:30:41 alvherre Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/plpgsql.sgml,v 1.138 2009/02/05 15:25:49 momjian Exp $ -->
22
33<chapter id="plpgsql">
44 <title><application>PL/pgSQL</application> - <acronym>SQL</acronym> Procedural Language</title>
@@ -1356,6 +1356,14 @@ GET DIAGNOSTICS integer_var = ROW_COUNT;
13561356 execution of other statements within the loop body.
13571357 </para>
13581358 </listitem>
1359+ <listitem>
1360+ <para>
1361+ A <command>RETURN QUERY</command> and <command>RETURN QUERY
1362+ EXECUTE</command> statements set <literal>FOUND</literal>
1363+ true if the query returns at least one row, false if no row
1364+ is returned.
1365+ </para>
1366+ </listitem>
13591367 </itemizedlist>
13601368
13611369 <literal>FOUND</literal> is a local variable within each
Original file line number Diff line number Diff line change 88 *
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.231 2009/01/21 11:13:14 heikki Exp $
11+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.232 2009/02/05 15:25:49 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -2286,6 +2286,7 @@ exec_stmt_return_query(PLpgSQL_execstate *estate,
22862286 PLpgSQL_stmt_return_query * stmt )
22872287{
22882288 Portal portal ;
2289+ uint32 processed = 0 ;
22892290
22902291 if (!estate -> retisset )
22912292 ereport (ERROR ,
@@ -2327,6 +2328,7 @@ exec_stmt_return_query(PLpgSQL_execstate *estate,
23272328 HeapTuple tuple = SPI_tuptable -> vals [i ];
23282329
23292330 tuplestore_puttuple (estate -> tuple_store , tuple );
2331+ processed ++ ;
23302332 }
23312333 MemoryContextSwitchTo (old_cxt );
23322334
@@ -2336,6 +2338,9 @@ exec_stmt_return_query(PLpgSQL_execstate *estate,
23362338 SPI_freetuptable (SPI_tuptable );
23372339 SPI_cursor_close (portal );
23382340
2341+ estate -> eval_processed = processed ;
2342+ exec_set_found (estate , processed != 0 );
2343+
23392344 return PLPGSQL_RC_OK ;
23402345}
23412346
Original file line number Diff line number Diff line change @@ -3666,3 +3666,35 @@ select * from tftest(10);
36663666(2 rows)
36673667
36683668drop function tftest(int);
3669+ create or replace function rttest()
3670+ returns setof int as $$
3671+ declare rc int;
3672+ begin
3673+ return query values(10),(20);
3674+ get diagnostics rc = row_count;
3675+ raise notice '% %', found, rc;
3676+ return query select * from (values(10),(20)) f(a) where false;
3677+ get diagnostics rc = row_count;
3678+ raise notice '% %', found, rc;
3679+ return query execute 'values(10),(20)';
3680+ get diagnostics rc = row_count;
3681+ raise notice '% %', found, rc;
3682+ return query execute 'select * from (values(10),(20)) f(a) where false';
3683+ get diagnostics rc = row_count;
3684+ raise notice '% %', found, rc;
3685+ end;
3686+ $$ language plpgsql;
3687+ select * from rttest();
3688+ NOTICE: t 2
3689+ NOTICE: f 0
3690+ NOTICE: t 2
3691+ NOTICE: f 0
3692+ rttest
3693+ --------
3694+ 10
3695+ 20
3696+ 10
3697+ 20
3698+ (4 rows)
3699+
3700+ drop function rttest();
Original file line number Diff line number Diff line change @@ -2948,3 +2948,27 @@ $$ language plpgsql immutable strict;
29482948select * from tftest(10 );
29492949
29502950drop function tftest(int );
2951+
2952+ create or replace function rttest ()
2953+ returns setof int as $$
2954+ declare rc int ;
2955+ begin
2956+ return query values (10 ),(20 );
2957+ get diagnostics rc = row_count;
2958+ raise notice ' % %' , found, rc;
2959+ return query select * from (values (10 ),(20 )) f(a) where false;
2960+ get diagnostics rc = row_count;
2961+ raise notice ' % %' , found, rc;
2962+ return query execute ' values(10),(20)' ;
2963+ get diagnostics rc = row_count;
2964+ raise notice ' % %' , found, rc;
2965+ return query execute ' select * from (values(10),(20)) f(a) where false' ;
2966+ get diagnostics rc = row_count;
2967+ raise notice ' % %' , found, rc;
2968+ end;
2969+ $$ language plpgsql;
2970+
2971+ select * from rttest();
2972+
2973+ drop function rttest();
2974+
You can’t perform that action at this time.
0 commit comments