Complete the code to enable row-level security on the table employees.
ALTER TABLE employees [1] ROW LEVEL SECURITY;To use row-level security, you must first enable it on the table with ALTER TABLE ... ENABLE ROW LEVEL SECURITY.
Complete the code to create a row-level security policy named user_policy on the employees table that allows users to see only their own rows based on user_id.
CREATE POLICY user_policy ON employees FOR SELECT TO PUBLIC USING (user_id = [1]);The function current_user returns the name of the current database user, which is commonly used in row-level security policies to filter rows.
Fix the error in the policy creation by completing the code to restrict UPDATE operations only to rows where user_id matches the current user.
CREATE POLICY update_policy ON employees FOR UPDATE TO PUBLIC USING ([1] = current_user);The policy must check the user_id column against the current user to restrict updates to their own rows.
Fill both blanks to create a policy named delete_policy that allows DELETE only for rows where user_id matches the current user and only for the role admin.
CREATE POLICY delete_policy ON employees FOR DELETE TO [1] USING (user_id = current_user AND role = [2]);
The policy applies to all users (TO PUBLIC) but restricts deletes to rows where role equals the string 'admin'.
Fill all three blanks to create a policy named select_policy that allows SELECT only for the role manager and only on rows where department matches the current user's department stored in current_setting('app.department').
CREATE POLICY select_policy ON employees FOR SELECT TO [1] USING (role = [2] AND department = [3]);
The policy applies to all users (TO PUBLIC), restricts to role 'manager', and matches the department column to the current user's department setting.