You can define a function that returns required limit for some users. The function below set limit for users joe
and ben
.
Note that limit null
is equivalent to limit all
, so all other users will have no limits.
create or replace function set_limit()
returns integer language sql as $$
select case current_user
when 'joe' then 100
when 'ben' then 200
else null
end
$$;
select * from some_table limit set_limit();
Edit:
So basically we would like to append a limit clause to any select query fired by a particular user.
Once function set_limit() is created you can append limit set_limit()
to any select query.