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

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐