You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 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);