Postgresql
解釋的 Postgres 權限
我想授予使用者執行
EXPLAIN
但不執行SELECT
自身的權限。這在 PostgreSQL 中可行嗎?
創建一個如下所示的函式;
CREATE OR REPLACE FUNCTION public.explain_this ( l_query text, out explain text ) RETURNS SETOF text AS $body$ BEGIN RETURN QUERY EXECUTE 'explain (ANALYZE FALSE) ' || l_query; END; $body$ LANGUAGE 'plpgsql' VOLATILE RETURNS NULL ON NULL INPUT SECURITY DEFINER COST 100 ROWS 1000;
然後安排特權;
ALTER FUNCTION public.explain_this(l_query text, out explain text) OWNER TO some_user_with_select_only_privileges; GRANT EXECUTE ON FUNCTION public.explain_this(l_query text, out explain text) TO user_to_execute;