Loop on tables with PL/pgSQL in Postgres 9.0+
I can’t remember the last time I actually needed to use an explicit cursor for looping in PL/pgSQL. Use the implicit cursor of a FOR loop, that’s much cleaner: DO $$ DECLARE rec record; nbrow bigint; BEGIN FOR rec IN SELECT * FROM pg_tables WHERE tablename NOT LIKE ‘pg\_%’ ORDER BY tablename LOOP EXECUTE ‘SELECT … Read more