postgresql中,對表的權限控制比較嚴格,很多事情只有owner才有權限去做。所以我們盡量用onwer賬戶去操作。
但是有的時候我們需求去批量修改owner,比如導入的表結構。但是官方並沒有提供比較好的命令。
我們可以用拼接sql的方式去完成這個命令。
1.查看有哪些表
select * from information_schema.tables where table_schema='public';
2.拼接sql
select 'ALTER TABLE ' || table_name || ' OWNER TO yourowner;' from information_schema.tables where table_schema='public';
3.報生成的sql 復制下來,執行即可