本文主要是介绍pgsql中表名或者修改字段,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
批量修改表名或字段
----------修改大小写begin------------创建方法修改表字段的大小写
CREATE OR REPLACE FUNCTION "public"."exec"("sqlstring" varchar)RETURNS "pg_catalog"."varchar" AS $BODY$declareres varchar(50);BEGINEXECUTE sqlstring;RETURN 'ok';END
$BODY$LANGUAGE plpgsql VOLATILECOST 100;-- 根据条件查询所有大写的column
select * from information_schema.columns where table_schema='public' and table_name<>'pg_stat_statements' and column_name <> lower(column_name);-- 修改条件后,通过下列语句转换column_name中的大写字母
SELECTexec('alter table "' || table_name || '" rename column "' || column_name || '" to ' || lower( column_name ) || ';')
FROMinformation_schema.COLUMNS
WHEREtable_schema = 'public' AND column_name <> lower(column_name)AND table_name <> 'pg_stat_statements' AND table_name in ('t_ga_rjbxx','t_ga_fwjbxx','sys_people_info','t_zp_edz','t_zp_jzz');-- 查询大写的table_name
SELECT * FROM information_schema.TABLES WHERE table_schema = 'public' AND table_catalog = 'Guns' AND table_name <> lower( table_name );-- 修改表名中的大写为小写
SELECTexec ( 'alter table "' || table_name || '" to ' || lower( table_name ) || ';' )
FROMinformation_schema.tables
WHEREtable_schema='public' and table_catalog = 'Guns' and table_name <> lower(table_name);----------修改大小写end----------
这篇关于pgsql中表名或者修改字段的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!