I have the below function. It is intended to loop through every schema and return all user IDs from a table in that schema. The schemas have the format: users[0-100].
$body$
declare
r varchar;
sql text := 'select userid from $1.users';
begin
for r in select schema_name from information_schema.schemata where schema_name ~ '^users'
loop
return query select format('select userid from %s.users', r);
end loop;
return;
end
$body$
I have tried a few different ways, but I haven't been able to return a set. Where am I going wrong?