From 6d92f2106fa840a497e3cdc88bb4883e9a4712e8 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Sun, 10 Jul 2005 15:19:43 +0000
Subject: The attached patch implements spi_query() and spi_fetchrow()
 functions for PL/Perl, to avoid loading the entire result set into memory as
 the existing spi_exec_query() function does.

Here's how one might use the new functions:

    $x = spi_query("select ...");
    while (defined ($y = spi_fetchrow($x))) {
        ...
        return_next(...);
    }

The changes do not affect the spi_exec_query() interface in any way.

Abhijit Menon-Sen
---
 src/pl/plperl/sql/plperl.sql | 13 +++++++++++++
 1 file changed, 13 insertions(+)

(limited to 'src/pl/plperl/sql/plperl.sql')

diff --git a/src/pl/plperl/sql/plperl.sql b/src/pl/plperl/sql/plperl.sql
index 3e601173ddf..3cafb590c76 100644
--- a/src/pl/plperl/sql/plperl.sql
+++ b/src/pl/plperl/sql/plperl.sql
@@ -247,3 +247,16 @@ for ("World", "PostgreSQL", "PL/Perl") {
 return;
 $$ language plperl;
 SELECT * from perl_srf_rn() AS (f1 INTEGER, f2 TEXT, f3 TEXT);
+
+--
+-- Test spi_query/spi_fetchrow
+--
+
+CREATE OR REPLACE FUNCTION perl_spi_func() RETURNS SETOF INTEGER AS $$
+$x = spi_query("select 1 as a union select 2 as a");
+while (defined ($y = spi_fetchrow($x))) {
+    return_next($y->{a});
+}
+return;
+$$ LANGUAGE plperl;
+SELECT * from perl_spi_func();
-- 
cgit v1.2.3

