dbTalk Databases Forums  

[BUGS] MOVE FIRST does not work in PL/pgSQL on refcursor

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] MOVE FIRST does not work in PL/pgSQL on refcursor in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ingo Schellhammer
 
Posts: n/a

Default [BUGS] MOVE FIRST does not work in PL/pgSQL on refcursor - 08-26-2004 , 02:19 AM






Hi folks,

I want to scroll through the results of the same query inside a PL/pgSQL
function several times and learned that cursors can help me doing that.
However, the command "MOVE FIRST FROM <refcursor>" is not accepted by
the parser. Likewise, I get a similar error message when using the FETCH
command together with BACKWARD or FIRST. Is that intended? Are refcursor
variables only usable for forward scrolling? If yes, is there another
way of looping through the results of the same query/cursor several times?

I attached the script in question below. It would be great if anybody
could help me with this bug/problem!

Cheers,

Ingo

--------------------------------------------------------------

Quote:
My PL/pgSQL script is as follows:
CREATE OR REPLACE FUNCTION get_matching_triangles_by_range()
RETURNS SETOF matchresulttype AS '
DECLARE
[...]
ltri_cursor refcursor;
BEGIN
last_code := -1;
FOR stri IN SELECT * FROM stri_geoms
LOOP
IF (stri.scode <> last_code) THEN
IF (last_code <> -1) THEN
CLOSE ltri_cursor;
END IF;
last_code := stri.scode;
OPEN ltri_cursor FOR SELECT * FROM direct_codes
WHERE
(iac_types = stri.iac_types);
ELSE
MOVE FIRST FROM ltri_cursor;
END IF;
FETCH ltri_cursor INTO ltri;
WHILE FOUND LOOP
[...]
FETCH ltri_cursor INTO ltri;
END LOOP;
END LOOP;

RETURN;
END;
' LANGUAGE plpgsql;


Quote:
I execute the function as follows, causing the following error message:
new_test_lib=# SELECT * FROM get_matching_triangles_by_range();
WARNING: Error occurred while executing PL/pgSQL function
get_matching_triangles_by_range
WARNING: line 36 at SQL statement
ERROR: parser: parse error at or near "FROM" at character 12




---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.