Bird
0
0

Given the table orders with RLS enabled and this policy:

medium📝 query result Q4 of 15
PostgreSQL - Roles and Security
Given the table orders with RLS enabled and this policy:
CREATE POLICY order_owner ON orders FOR SELECT USING (owner = current_user);

What will the query SELECT * FROM orders; return when run by user alice?
ANo rows, because no policy allows access.
BAll rows in the orders table.
COnly rows where the owner column equals 'alice'.
DAn error because the policy is incomplete.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the policy effect

    The policy allows SELECT only on rows where owner = current_user.
  2. Step 2: Apply policy for user 'alice'

    When alice runs the query, only rows with owner = 'alice' are visible.
  3. Final Answer:

    Only rows where the owner column equals 'alice'. -> Option C
  4. Quick Check:

    RLS filters rows by owner = current_user = Only rows where the owner column equals 'alice'. [OK]
Quick Trick: RLS filters rows based on policy condition for current user. [OK]
Common Mistakes:
  • Assuming all rows are visible
  • Expecting an error due to policy
  • Thinking no rows are returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes