I've got a table that contains 20+ millions records and I'm trying to dump its data to a file. I've tried to use the cursor approach because of the memory issues.
How do you keep looping on the cursor until it reaches the end of the result set?
Here's my code
CREATE OR REPLACE FUNCTION gelargedata()
RETURNS SETOF mytable AS $$
OPEN cur FOR SELECT * FROM mytable;
FETCH FORWARD 1000 FROM cur;
IF not found THEN
$$ LANGUAGE 'PLPGSQL';