Database & SQL

Moderators: None (Apply to moderate this forum)
Number of threads: 1174
Number of posts: 2221

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
postgresql: USING CURSOR in extracting data in one database and insert Posted by kayoobi on 16 Mar 2011 at 8:45 PM
here is another algorithm using cursor but im having a hard time fixing its error...

    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;



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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.