Bird
0
0

Given the following policy on table documents:

medium📝 query result Q13 of 15
PostgreSQL - Roles and Security
Given the following policy on table documents:
CREATE POLICY user_policy ON documents
FOR SELECT USING (owner = current_user);
What rows will a user see when they run SELECT * FROM documents;?
AOnly rows where the owner column matches the current user
BNo rows, because no policy allows access
CAll rows in the documents table
DOnly rows where owner is NULL
Step-by-Step Solution
Solution:
  1. Step 1: Understand the policy condition

    The policy allows SELECT only if owner = current_user, so only rows owned by the current user are visible.
  2. Step 2: Determine visible rows

    Rows where the owner matches the current user will be returned; others are filtered out.
  3. Final Answer:

    Only rows where the owner column matches the current user -> Option A
  4. Quick Check:

    Policy filters rows by owner = current_user [OK]
Quick Trick: Policy USING clause filters rows visible to current_user [OK]
Common Mistakes:
  • Assuming all rows are visible despite policy
  • Thinking NULL owners are included
  • Ignoring the current_user condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes