0
create table user_table(
    idx text,
    _section text[]
);

create table section_table(
    _section text,
    sub_section text[]
);

alter table user_table enable row level security;

create policy user_p on user_table for select
using (section @> 
         (select _section from user_table 
            intersect
            (select _section::text[]
               from section_table 
               where current_setting('my.sub_section',true)::text[]
                     <@ (select sub_section 
                         from section_table)
            )
         )
      );

insert into user_table values
   (1,'{"section1"}'),(2,'{"section2"}'), 
   (2,'{"section2","section1"}');

insert into section_table values
   ('section1','{"s","b"}'), 
   ('section2','{"c","d"}');

期望输出:

set my.sub_section ='{"c"}';
select * from user_table;

应该只显示(2,'{"section2"}'),但它显示了一切。

输入的时候sub_section,应该去section_table找到对应的section和intersect user_table,一旦intersect的值不为null,那么应该返回对应的值 user_table

我很困惑为什么它没有显示正确的预期结果。

4

0 回答 0