I'm trying to achieve a way to create multiple indexes for multiple tables in Postgresql.
For now, i wrote something like this
do $$
declare temprow record;
declare idx_name character varying(200);
begin
for temprow in
select table_name from information_schema.tables where table_schema = 'public' and table_name like 'prefix%' order by table_name
loop
idx_name := 'index_name_prefix_' || temprow.table_name || '_idx';
create index idx_name ON temprow.table_name (column1 asc, column2 desc);
end loop;
end$$;
Seems like this should work, but it doesn't with an error
ERROR: schema "temprow" does not exist
I thought i would just schedule this sql once a week, as that's a proper way for my task
Can you help me to find error in this SQL or suggest a better way to create indexes for multiple tables?