Using cursors inside PL/pgSQL function

From: "Atul" <atulk(at)newgen(dot)co(dot)in>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Using cursors inside PL/pgSQL function
Date: 2001-04-23 06:54:29
Message-ID: 003001c0cbc2$3e3c3140$5e05a8c0@atul
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Can't we use cursors inside pl/pgSQL functions. I tried defining the transaction with Begin work and end work statements, because the documentation says that cursors can only be defined in these blocks. But this does not work. I have the following code :

create function sample() returns text as '
declare
retValue text;
begin work
declare retCur Cursor for select * from <table name>;
Fetch 1 in retCur;
close retCur;
return ''abc'';
end work;'
language 'plpgsql';

When i execute the above it says ' parse error at or near "work" '. I know that in plpgsql function only begin and end keywords define the block, but since I need to retrieve the value one by one from the table I need to do this.

Is it possible to do the above? If yes, how can I return the value retrieved from the table, from the function?

Regards,

Atul

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message suhail sarwar 2001-04-23 13:04:53 Java Interface for postgres database
Previous Message Joel Burton 2001-04-23 02:06:31 Re: CAST doesn't work :-( (fwd)