Created
April 3, 2022 20:41
-
-
Save YPermitin/f47a2e9e29140c414919ccc51b54b36d to your computer and use it in GitHub Desktop.
Пример курсора для PostgreSQL (plpgsql)
This file contains 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
do $$ | |
declare | |
text_result text default ''; | |
rec_someval record; | |
dt_cursor cursor for | |
select | |
tablename AS table_name | |
from pg_catalog.pg_tables | |
order by tablename; | |
begin | |
open dt_cursor; | |
loop | |
fetch dt_cursor into rec_someval; | |
exit when not found; | |
text_result := text_result || chr(10) || rec_someval.table_name::text; | |
end loop; | |
close dt_cursor; | |
RAISE NOTICE '%', text_result; | |
end | |
$$ language 'plpgsql'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment