0
0
PostgreSQLquery~5 mins

Row-level security policies in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a row-level security policy in PostgreSQL?
A row-level security policy controls which rows a user can see or modify in a table, based on rules defined by the database administrator.
Click to reveal answer
beginner
How do you enable row-level security on a PostgreSQL table?
Use the command ALTER TABLE table_name ENABLE ROW LEVEL SECURITY; to turn on row-level security for that table.
Click to reveal answer
intermediate
What is the purpose of a policy in row-level security?
A policy defines the conditions under which rows are visible or modifiable by users. It acts like a filter for rows based on user roles or other criteria.
Click to reveal answer
intermediate
How do you create a row-level security policy in PostgreSQL?
Use CREATE POLICY policy_name ON table_name FOR {SELECT | INSERT | UPDATE | DELETE} TO role_name USING (condition); to define who can access which rows and how.
Click to reveal answer
advanced
Can a user bypass row-level security policies in PostgreSQL?
Yes, users with the BYPASSRLS privilege can bypass row-level security policies and see all rows regardless of policies.
Click to reveal answer
Which command enables row-level security on a PostgreSQL table?
AALTER TABLE table_name ENABLE ROW LEVEL SECURITY;
BCREATE POLICY ON table_name;
CGRANT SELECT ON table_name;
DALTER TABLE table_name SET SECURITY POLICY;
What does a row-level security policy control?
AWhich columns a user can see
BWhich rows a user can see or modify
CWhich tables a user can access
DThe database connection settings
Which privilege allows a user to bypass row-level security policies?
ASUPERUSER
BADMIN
CBYPASSRLS
DSECURITY_ADMIN
In the command CREATE POLICY, what does the USING clause specify?
AThe condition to filter rows
BThe columns to include
CThe user roles allowed
DThe table name
Can row-level security policies be applied to INSERT operations?
ANo, only SELECT operations are controlled
BPolicies only apply to SELECT and UPDATE
COnly UPDATE and DELETE are controlled
DYes, policies can control INSERT, SELECT, UPDATE, and DELETE
Explain what row-level security policies are and why they are useful in PostgreSQL.
Think about how you can limit what data different users see in the same table.
You got /4 concepts.
    Describe the steps to enable and create a row-level security policy on a table in PostgreSQL.
    Start with enabling, then define who can do what on which rows.
    You got /5 concepts.