Thread: Cursor problem
Hello All,
How do I create a cursor in psql .
I have a function which opens a cursor .
SampleDB=# create function reffunc(refcursor) returns refcursor as $$
SampleDB$# begin
SampleDB$# open $1 for select col from test;
SampleDB$# return $1;
SampleDB$# end;
SampleDB$# $$ language sql;
ERROR: syntax error at or near "open" at character 67
LINE 3: open $1 for select col from test;
SampleDB$# begin
SampleDB$# open $1 for select col from test;
SampleDB$# return $1;
SampleDB$# end;
SampleDB$# $$ language sql;
ERROR: syntax error at or near "open" at character 67
LINE 3: open $1 for select col from test;
I am not able to create a cursor , it errors out at 'open '
I tried a still more simple one
^
SampleDB=# create or replace function test(refcursor) returns refcursor as $$
SampleDB=# create or replace function test(refcursor) returns refcursor as $$
SampleDB=#begin
SampleDB$# syscur refcursor;
SampleDB$# syscur refcursor;
SampleDB=#end;
SampleDB$# $$ language sql;
ERROR: syntax error at or near "syscur" at character 68
LINE 2: syscur refcursor;
SampleDB$# $$ language sql;
ERROR: syntax error at or near "syscur" at character 68
LINE 2: syscur refcursor;
How do I create a cursor .
Any help asap ?
Thanks
Vidya
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
On Fri, May 06, 2005 at 05:58:11AM -0700, Vidya wrote: > > How do I create a cursor in psql . > > I have a function which opens a cursor . > SampleDB=# create function reffunc(refcursor) returns refcursor as $$ > SampleDB$# begin > SampleDB$# open $1 for select col from test; > SampleDB$# return $1; > SampleDB$# end; > SampleDB$# $$ language sql; > ERROR: syntax error at or near "open" at character 67 > LINE 3: open $1 for select col from test; In this example the function's language should be plpgsql, not sql. For more information about returning cursors from a PL/pgSQL function, see the documentation: http://www.postgresql.org/docs/8.0/interactive/plpgsql-cursors.html -- Michael Fuhr http://www.fuhr.org/~mfuhr/