On Feb 24, 2025, at 06:18, Point Lamont <
point...@gmail.com> wrote:
> I was wondering on how to impersonate a user to test a function.
>
> Suppose I have a role 'user' and and two users: userA and userB with role 'user'.
> And a function that returns "TRUE" if it is executed by user userA and "FALSE" if by userB.
> Row level security is enabled.
Sure. Just use SET ROLE[1] to the user you want to use, something like:
```sql
SET ROLE userA;
SELECT ok(myfunc(), 'User A gets true');
SET ROLE userB;
SELECT ok(NOT myfunc(), 'User A gets true');
Best,
David
[1]:
https://www.postgresql.org/docs/current/sql-set-role.html