I want to write function for postgresql 10 to grant read-only access to on all databases for the specified user (considerably should be run from superuser)
But I have difficulties in database switching part. I try to switch the database inside a cursor but I get an error I can't understand. How can I correct my script?
CONTEXT: PL/pgSQL function inline_code_block at EXECUTE
DO $$
DECLARE query text;
cursor cursor
FOR
SELECT '\c '||datname ||';' from pg_database;
BEGIN
OPEN cursor;
LOOP
FETCH cursor INTO query;
EXIT WHEN NOT FOUND;
--raise notice 'Value: %',query;
EXECUTE query;
END LOOP;
CLOSE cursor;
END $$;