Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f3RIMM329705 for ; Fri, 27 Apr 2001 14:22:22 -0400 (EDT) (envelope-from pgsql-interfaces-owner@postgresql.org) Received: from office.price.ru (office.price.ru [195.209.34.132]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3RE9T315291 for ; Fri, 27 Apr 2001 10:09:29 -0400 (EDT) (envelope-from alexey@workshop.price.ru) Received: from workshop.price.ru ([195.209.34.137] ident=alexey) by office.price.ru with esmtp (Exim 3.22 #1) id 14t8w0-00056X-00 for pgsql-interfaces@postgresql.org; Fri, 27 Apr 2001 18:09:24 +0400 Received: by workshop.price.ru (8.9.3+Sun/8.9.1) id SAA15511 for pgsql-interfaces@postgresql.org; Fri, 27 Apr 2001 18:09:22 +0400 (MSD) From: Alexey Nalbat Reply-To: alexey@price.ru Organization: Price Express To: pgsql-interfaces@postgresql.org Subject: Re: can external C-function get multiple rows? Date: Fri, 27 Apr 2001 16:50:21 +0400 X-Mailer: KMail [version 1.0.28] Content-Type: text/plain; charset="koi8-r" References: <01042420581800.12729@workshop.price.ru> <16102.988296940@sss.pgh.pa.us> In-Reply-To: <16102.988296940@sss.pgh.pa.us> MIME-Version: 1.0 Message-Id: <01042718092204.12343@workshop.price.ru> Content-Transfer-Encoding: 8bit X-Archive-Number: 200104/127 X-Sequence-Number: 1511 Tom, thank you very much. I was succeeded in constructing such a test function. And now have another question. I wrote function myarr(foo) which returns exactly 10 rows of random values in the range [0,foo). But I also want this function to work correctly, when used in a query with limit clause, like "select myarr(100) limit 6;". After a bit of experiments I supposed that while executing this query postgres called myarr() seven times (not six!). And may be at the seven call fcinfo has some_flag set to "stop_return", after checking which myarr() should do the same as when returning 11's row with PG_RETURN_NULL and setting "isDone" to "ExprEndResult" and resetting variables. Is it so? What are some_flag and "stop_return"? Thanks in advance. P.S.: Now myarr() does not reset variables when "interrupted by limit", and because of this returns: +++ +++ pl=# select myarr(100) limit 6; ?column? ---------- 87 42 35 38 4 16 (6 rows) pl=# select myarr(100) limit 6; ?column? ---------- 69 9 40 (3 rows) +++ +++ Here is myarr() code: +++ +++ #include #include "postgres.h" #include "fmgr.h" #include "nodes/execnodes.h" #define N 10 int a_c[N]; int n_c=0; int i_c=0; PG_FUNCTION_INFO_V1(myarr); Datum myarr(PG_FUNCTION_ARGS) { int n=PG_GETARG_INT32(0); if ( n_c!=n ) { int j; n_c=n; i_c=0; for ( j=0 ; jresultinfo)->isDone=ExprMultipleResult; PG_RETURN_INT32(a_c[i_c-1]); } else { n_c=0; i_c=0; ((ReturnSetInfo*)fcinfo->resultinfo)->isDone=ExprEndResult; PG_RETURN_NULL(); } } +++ +++ -- WBR, Alexey Nalbat