X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7408FD1B513 for ; Tue, 23 Sep 2003 11:41:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 88650-05 for ; Tue, 23 Sep 2003 08:41:27 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id 1DF2FD1B58D for ; Tue, 23 Sep 2003 08:41:23 -0300 (ADT) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 0643D2B3D6 for ; Tue, 23 Sep 2003 13:41:09 +0200 (CEST) Message-ID: <3F70314C.30507@klaster.net> Date: Tue, 23 Sep 2003 13:41:00 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5a) Gecko/20030718 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: Lista dyskusyjna pgsql-sql Subject: pl/pgsql, cursors and C function Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/270 X-Sequence-Number: 15248 Hi I'm making my first steps in C functions. I want to avoid doing all the SQL job in them, pl/pgsql looks a better choice. I tried to do this by passing opened cursor from pl/pgsql function to C function. Here is simple C function: #include #include PG_FUNCTION_INFO_V1(test2); Datum test2(PG_FUNCTION_ARGS) { Portal p; int n; p=SPI_cursor_find("xxx"); if(!p) elog(ERROR,"Cursor error"); SPI_cursor_fetch(p,true,1); n=SPI_processed; PG_RETURN_INT32(n); } And pl/pgsql one: CREATE OR REPLACE FUNCTION test() returns integer AS ' DECLARE _m CURSOR FOR select id from some_table limit 1; n integer; BEGIN _m=''xxx''; open _m; n=test2(); close _m; return n; END; ' language 'plpgsql'; select test(); I don't understand ERROR message at all: ERROR: SPI_prepare() failed on "SELECT $1 " This error is raised when trying to execute SPI_cursor_fetch. What does it mean? What does the SPI_prepare have to already opened cursor? Where can I find better SPI documentation than "Postgresql Server Programming" ? Regards, Tomasz Myrta