[转][postgresql]转换表名为小写
作者:互联网
转自:https://www.cnblogs.com/heibai-ma/p/13675068.html
-- 创建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_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) --AND table_name like '%'; -- 查询表名中的大写 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);
亲测可用
标签:lower,postgresql,name,column,--,小写,table,名为,schema 来源: https://www.cnblogs.com/z5337/p/14347969.html