postgresql数据库表名大小写转换简单方式(DO块)
这是转小写,需要转换为大写时lower改为upper,数字和中文表名自动无效。
·
yours_schema改成你自己的模式名。这是转小写,需要转换为大写时lower改为upper,数字和中文表名自动无效
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'yours_schema') LOOP
EXECUTE 'ALTER TABLE yours_schema.' || quote_ident(r.table_name) || ' RENAME TO ' || quote_ident('wangxang_' || r.table_name);
END LOOP;
FOR r IN (SELECT table_name FROM information_schema.tables WHERE table_schema = 'yours_schema' AND table_name LIKE 'wangxang_%') LOOP
EXECUTE 'ALTER TABLE yours_schema.' || quote_ident(r.table_name) || ' RENAME TO ' || quote_ident(lower(substring(r.table_name FROM 11)));
END LOOP;
END $$;
更多推荐
已为社区贡献1条内容
所有评论(0)