Reputation: 1108
What is the difference in looping over query result vs looping over explicitly declared cursor in Postgres? Is looping over query result implicitly creating a cursor?
Looping over query result:
FOR v_employee IN
SELECT *
FROM employee
WHERE ...
LOOP
-- Do something with v_employee
END LOOP;
Looping over explicitly declared cursor:
FOR v_employee IN my_cursor
LOOP
-- Do something with v_employee
END LOOP;
Upvotes: 1
Views: 82
Reputation: 247270
Yes, looping through a query result will use a cursor implicitly.
The performance should be the same, but the first syntax is often clearer.
Upvotes: 1