postgresql 如何在Postgres中授予以宗地开头的表的权限?

46qrfjad  于 2023-02-04  发布在  PostgreSQL
关注(0)|答案(1)|浏览(93)
GRANT UPDATE 
ON (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'parcel%') 
TO police;
baubqpgj

baubqpgj1#

GRANT只接受文本表名。您需要动态SQL,即动态构建语句并在匿名块中执行它。
考虑:

do
$$
begin
    execute (
        select 
            'grant all on table '
            || string_agg (format('%I.%I', table_schema, table_name), ', ')
            || ' to police'
        from information_schema.tables
        where table_name like 'parcel%'
    );
end
$$;

相关问题