Using PostgreSQL, is it somehow possible to restrict the SELECT privilege of a certain user so that he can only select a certain limited number of rows from a certain table?
For example, user joe should be allowed to execute
SELECT * FROM my_table WHERE id = 17;
but at the same time should not be allowed to execute (because it matches more than 1 row)
SELECT * FROM my_table;
To clarify, id = 17 is of course just an example here. I'm actually looking for a way to allow joe to execute SELECT ... FROM my_table WHERE ... only if the query returns at most one row. I obviously can't simply use GRANT SELECT ON my_table TO joe to solve this, but is it still somehow possible?
LIMITrelate to access privileges?count(*) <= 1as constraint. Please provide enough info, because it is unclear how you would create this constraint.constraint- OP seems to be looking for a way to constrain/restrict a user, imposing a limit of how many rows they are allowed to get at any time from a given table. Whether that's going to be handled by RLS, the privilege system, a routine, a rule, a view or a configuration setting, is less important, since it's not immediately obvious how to do that with any of these. Except by revoking all access and forcing the user to interface with everything through functions that strap on alimitclause everywhere.