说我有桌子:
Fee
date : DATE
amount : INT
我无法以原始方式将数据存储在amount
列中,因为这是私有信息,因此我需要对其进行加密。此外,我需要对该加密列执行算术运算,如:
SELECT SUM(amount) FROM Fee;
最好的方法是什么?谢谢。
答案 0 :(得分:1)
为什么不使用Postgres的内置列级安全性?
代码:
create table employees (
id int primary key,
name text not null,
salary decimal(10,2) not null
);
insert into employees values (1, 'Frank', 60000.00);
create or replace view employees_view as
select
id,
name,
case when has_column_privilege('employees', 'salary', 'select') then salary else null end as salary
from employees;
create role managers;
create role clerks;
grant select on employees_view to managers;
grant select on employees_view to clerks;
grant select (salary) on employees to managers;
set role managers;
select * from employees_view;
结果:1,' Frank',60000.00
set role clerks;
select * from employees_view;
结果:1,' Frank',null