Last active
December 17, 2019 07:23
-
-
Save schaary/33e219427c1459ab09e2c29295d5cc1b to your computer and use it in GitHub Desktop.
for loop to fetch records from select in postgresql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- An implicite cursor in PostgreSQL PLPGSQL. | |
-- | |
-- The main idea is to declare a cursor in the loop header | |
-- and fetch the rows inside the loop | |
do $$ | |
declare | |
rec record; | |
begin | |
for rec in | |
select * | |
from accounts | |
order by lastname, firstname | |
loop | |
raise notice '% - %', rec.firstname, rec.lastname; | |
end loop; | |
end | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment