W
Size: a a a
W
MC
2_
security definer
и дав права на эту функцию.sudo -u postgres psql
create table public.test as select * from (values (cast(1 as int)), (2), (3)) as t(col1);
create or replace function public.fTest()
returns table (a int) external security definer
as $$
begin return query select a from public.test; end
$$
language plpgsql;
create role sql_reporting_services with login password '12345';
grant execute on function public.fTest() to sql_reporting_services;
quit;
psql -h 127.0.0.1 -U sql_reporting_services -d car_app_portal
Результат: select * from public.fTest();
ERROR: permission denied for table test
CONTEXT: SQL statement "select a from public.test"```
PL/pgSQL function ftest() line 2 at RETURN QUERY
MC
2_
W
2_
W
MC
\connect car_app_portal
select current_user;
current_user
--------------
postgres
(1 row)
postgres=# \connect car_app_portal
You are now connected to database "car_app_portal" as user "postgres".
car_app_portal=# select * from public.test ;
col1
------
1
2
3
(3 rows)
car_app_portal=# select * from public.ftest() ;
a
---
(3 rows)
W
MC
W
2_
W
2_
MC
security definer
и дав права на эту функцию.sudo -u postgres psql
create table public.test as select * from (values (cast(1 as int)), (2), (3)) as t(col1);
create or replace function public.fTest()
returns table (a int) external security definer
as $$
begin return query select a from public.test; end
$$
language plpgsql;
create role sql_reporting_services with login password '12345';
grant execute on function public.fTest() to sql_reporting_services;
quit;
psql -h 127.0.0.1 -U sql_reporting_services -d car_app_portal
Результат: select * from public.fTest();
ERROR: permission denied for table test
CONTEXT: SQL statement "select a from public.test"```
PL/pgSQL function ftest() line 2 at RETURN QUERY
2_
MC
\df ftest
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+-------+------------------+---------------------+------
public | ftest | TABLE(a integer) | | func
(1 row)
W
W