代码
DO $ DECLARE row record; BEGIN FOR row IN SELECT table_schema,table_name,column_name FROM information_schema.columns WHERE table_schema = 'public' and column_name <> lower(column_name) LOOP EXECUTE format('ALTER TABLE %I.%I RENAME COLUMN %I TO %I', row.table_schema,row.table_name,row.column_name,lower(row.column_name)); END LOOP; END $;
说明 使用 do loop 循环 查找columns的表 然后使用alerter table进行转换