0

I am using row level security with function, for example

CREATE POLICY person_select_policy ON core.person FOR SELECT USING (core.person_policy_check(id, 'read') = TRUE);

Is it possible to pass whole row to the function? So the function would have access to all columns of the row without having to name them all as arguments. That way the function could accept core.person as parameter or at least a record type.

1 Answers1

1

Yes, that's possible. Declare a parameter with the type of the table:

create function core.person_policy_check(p_row core.person, p_access text)
  returns boolean
as
$$
begin
  if p_row.id = 42 then ..
end
$$
language plpgsql;

Then pass the row to the function:

CREATE POLICY person_select_policy 
   ON core.person 
   FOR SELECT USING (core.person_policy_check(person, 'read') = TRUE);