You can use a `DO` statement to run a single dynamic command: DO $do$ BEGIN RAISE NOTICE '%', ( -- EXECUTE ( SELECT string_agg(format('ALTER TABLE %s ALTER COLUMN %I TYPE text' , a.attrelid::regclass, a.attname), E';\n') FROM pg_attribute a JOIN pg_class c ON c.oid = a.attrelid JOIN pg_namespace n ON n.oid = c.relnamespace WHERE a.attname = 'description' AND a.atttypid = 'varchar'::regtype AND format_type(a.atttypid, a.atttypmod) = 'character varying(255)' AND n.nspname NOT LIKE ALL ('{pg_%, information_schema}'::text[]) ); END $do$; Since the command is potentially hazardous I commented the `EXECUTE` and put a `RAISE NOTICE` there instead. After confirming the commands are sane, switch the comment to actually execute the DDL commands. This changes the type for all columns `description varchar(255)`, except for those in system catalogs, temporary tables (both starting with 'pg_' and the information schema.