Bird
0
0

Which of the following is the correct syntax to create a row-level security policy named user_policy on table files allowing users to access only their own rows based on user_id?

easy📝 Syntax Q3 of 15
PostgreSQL - Roles and Security
Which of the following is the correct syntax to create a row-level security policy named user_policy on table files allowing users to access only their own rows based on user_id?
ACREATE POLICY user_policy ON files FOR ALL TO current_user USING (user_id = current_user);
BCREATE POLICY user_policy ON files FOR SELECT USING (user_id = session_user);
CCREATE POLICY user_policy ON files FOR SELECT TO public USING (user_id = current_user);
DCREATE POLICY user_policy ON files FOR SELECT USING (user_id = current_user);
Step-by-Step Solution
Solution:
  1. Step 1: Understand policy syntax

    Policy syntax is: CREATE POLICY name ON table FOR command USING (condition);
  2. Step 2: Check condition and user context

    Using user_id = current_user restricts rows to current user. CREATE POLICY user_policy ON files FOR SELECT USING (user_id = current_user); matches this correctly.
  3. Final Answer:

    CREATE POLICY user_policy ON files FOR SELECT USING (user_id = current_user); -> Option D
  4. Quick Check:

    Policy syntax with USING and current_user = CREATE POLICY user_policy ON files FOR SELECT USING (user_id = current_user); [OK]
Quick Trick: Use USING clause with current_user to filter rows per user. [OK]
Common Mistakes:
  • Adding TO clause incorrectly
  • Using session_user instead of current_user
  • Wrong FOR command or missing USING

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes