-- PG 统一将表及字段名改为小写字母
-- 创建exec(sqlstring)函数方便执行
CREATE OR REPLACE FUNCTION "public"."exec"("sqlstring" varchar)
  RETURNS "pg_catalog"."varchar" AS $BODY$
    declare
        res varchar(50);
    BEGIN
        EXECUTE sqlstring;
        RETURN 'ok';
    END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100
  
-- 根据条件查询指定的表，所有大写的column
select * from information_schema.columns where table_schema = 'public'

-- 修改条件后，通过下列语句转换column_name中的大写字母
SELECT
    exec('alter table "' || table_name || '" rename column  "' || column_name || '" to ' || lower( column_name ) || ';')
FROM
    information_schema.COLUMNS 
WHERE
    table_schema = 'public' 
    AND column_name <> lower(column_name);
    
    
-- 查询大写的table_name
SELECT * FROM information_schema.TABLES WHERE   table_schema = 'public' AND table_catalog = '库名' AND table_name <> lower( table_name );

-- 修改表名中的大写为小写
SELECT
    exec ( 'alter table "' || table_name || '" rename to ' || lower( table_name ) || ';' ) 
FROM
    information_schema.tables 
WHERE
    table_schema='public' 
    and table_catalog = '库名' 
    and table_name <> lower(table_name);