postgresql: USING CURSOR in extracting data in one database and insert - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

postgresql: USING CURSOR in extracting data in one database and insert

kayoobikayoobi Posts: 2Member
here is another algorithm using cursor but im having a hard time fixing its error...

[code]
CREATE OR REPLACE FUNCTION extractstudent()
RETURNS VOID AS
$BODY$
DECLARE
studcur SCROLL cursor FOR SELECT fname, lname, mname, address FROM student;
BEGIN
open studcur;

Loop
--fetching 1 row at a time
FETCH First FROM studcur;
--every row fetched is being inserted to another database on the local site
--myconT is the name of the connection to the other database in the local site
execute 'SELECT * from dblink_exec(''myconT'', ''insert into temp_student values(studcur)'')';
--move to the next row and execute again
move next from studcur;
--exit when the row content is already empty
exit when studcur is null;
end loop;

close studcur;

END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION extractstudent() OWNER TO postgres;[/code]


im just new in postgresql and i know this code has alot of error
hopefully someone can help me figure them out

thanks for dropping by

Sign In or Register to comment.