plpgsql - postgresql: USING CURSOR for extracting data from one database and inserting them to another -


There is another algorithm using the cursor here, but I'm having difficulty determining its error ...

  make or change the extractstant (function); Student pays the scroll carrier as $ body for Address Fan, Long, Manno, address; BEGIN open studs; Loop - use 1 row at a time; Pre-studs; - Every row is being found in any other database on the local site - MyconT is the name of the connection to other databases on the local site 'SELECT * to dblink_exec (' myconT '', 'Enter values ​​in temp_student (studcur)' ')'; Proceed to the next line and then proceed with the studs again; - When empty content is already empty, the studcur is zero; End loop; Close studs; End; $ Body $ LANGUAGE plpgsql quantitative cost 100; Owner for change function extractistudent () posts; You rarely need to use the cursor in postgresql or pl / pgsql.   is. What you have written looks suspicious, such as creating a SQL Server cursor loop, and you do not need to do this. In addition, you can use "PERFORM" instead of "PERFORM" to run the query and leave the results: it would want to refrain from re-parsing the query every time (although it avoids querying each time query Can not)  

You can do something else like this:

  DECLARE REC student% rowtype; To select, enter the student 'loop performance' dblink_exec ('mycont', 'temp_student values' in' quote_nullable (rec.fname)) ',' quote_nullable (rec.lname) || ',' | | Quote_nullable (rec.mname) || ',' || quote_nullable (rec.address) || ')'); End loop; End;    

Comments