当前位置:网站首页>Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
Oracle中已定义者身份执行函数AUTHID DEFINER与Postgresql行为的异同
2022-07-01 22:57:00 【mingjie73】
Oracle行为
Oracle中函数可以定义执行函数体时,使用哪个用户的权限:
[AUTHID { CURRENT_USER|DEFINER}]
CURRENT_USER已当前用户身份执行函数体
DEFINER已定义者的身份执行函数体
CASE1:例如下面函数会使用当前用户执行函数体,如果当前用户对tbl1读权限就可以成功执行。
CREATE OR REPLACE PROCEDURE TEST_P AUTHID CURRENT_USER IS
BEGIN
EXECUTE IMMEDIATE 'select * from tbl1';
END TEST_P;
CASE2:下面函数会使用定义函数的用户执行函数体,如果定义函数的用户对tbl1读权限就可以成功执行。
CREATE OR REPLACE PROCEDURE TEST_P AUTHID DEFINER IS
BEGIN
EXECUTE IMMEDIATE 'select * from tbl1';
END TEST_P;
PG 行为
PG中执行函数永远是使用当前用户的权限来执行的,类似Oracle中AUTHID CURRENT_USER的概念。
例如user1创建表
drop table u1tbl;
create table u1tbl(i int);
insert into u1tbl values (123);
user2无权限查询
postgres=> select * from u1tbl;
ERROR: permission denied for table u1tbl
user1创建函数
drop function f1();
CREATE OR REPLACE FUNCTION f1() RETURNS int AS $$
DECLARE
id int;
BEGIN
select i into id from u1tbl;
return id;
END;
$$ LANGUAGE plpgsql;
user2执行函数
postgres=> select f1();
ERROR: permission denied for table u1tbl
CONTEXT: SQL statement "select i from u1tbl"
PL/pgSQL function f1() line 5 at SQL statement
可见PG中并没有提供已定义者身份执行的这种方式。
边栏推荐
猜你喜欢

Istio, ebpf and rsocket Broker: in depth study of service grid
![[MySQL] basic use of explain and the function of each column](/img/d6/64f65ba21f5cda2c409477705f6a79.png)
[MySQL] basic use of explain and the function of each column

Experience of practical learning of Silicon Valley products

Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?

Notes on problems - /usr/bin/perl is needed by mysql-server-5.1.73-1 glibc23.x86_ sixty-four

Why is PHP called hypertext preprocessor

2022年起重机司机(限桥式起重机)考试试题及模拟考试

What is the relationship between modeling and later film and television?
![Compare the version number [double pointer to intercept the string you want]](/img/19/4f858ffdc1281d6b8b18a996467f10.png)
Compare the version number [double pointer to intercept the string you want]

Development trend and future direction of neural network Internet of things
随机推荐
2022 crane driver (limited to bridge crane) examination questions and simulation examination
Commemorate becoming the first dayus200 tripartite demo contributor
Is it safe to choose mobile phone for stock trading account opening in Shanghai?
MySQL -- convert rownum in Oracle to MySQL
y53.第三章 Kubernetes从入门到精通 -- ingress(二六)
2022年起重机司机(限桥式起重机)考试试题及模拟考试
Advanced skills of testers: a guide to the application of unit test reports
Openresty load balancing
Redis data types and application scenarios
每日三题 6.29
什么是马赛克?
为什么PHP叫超文本预处理器
Timer和ScheduledThreadPoolExecutor的区别
通过Go语言创建CA与签发证书
认识线程
Jielizhi, production line assembly link [chapter]
数字峰会人气火爆,城链科技引发新一轮商业变革
云信小课堂 | IM及音视频中常见的认知误区
JS - use of arguments
dat.GUI