What if you could share data safely without making endless copies or risking leaks?
Why Column-level permissions in PostgreSQL? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you have a big spreadsheet with sensitive columns like salaries or personal IDs. You want to share it with your team, but only let some people see certain columns. So, you try copying the sheet multiple times, deleting columns for each person manually.
This manual way is slow and risky. You might forget to remove a sensitive column, or accidentally share the wrong version. Every time data changes, you must repeat the process, which wastes time and causes mistakes.
Column-level permissions let you control who sees which columns directly in the database. You set rules once, and the database automatically hides sensitive columns from unauthorized users. This keeps data safe and saves you from repetitive work.
CREATE VIEW team_view AS SELECT name, salary FROM employees; -- create separate views for each permission setGRANT SELECT (name) ON employees TO team_member; GRANT SELECT (name, salary) ON employees TO manager;
It enables secure, flexible data sharing by controlling access to specific columns without duplicating data.
A hospital database lets doctors see patient names and medical history but hides billing info, while accountants see billing but not medical details.
Manual column filtering is slow and error-prone.
Column-level permissions automate and secure access control.
This protects sensitive data while sharing only what's needed.
Practice
Solution
Step 1: Understand the concept of column-level permissions
Column-level permissions allow control over which columns a user can see or modify in a table.Step 2: Compare with other access types
Other options refer to broader or unrelated access controls, not specific columns.Final Answer:
Access to specific columns in a table -> Option DQuick Check:
Column-level permission = Access to specific columns [OK]
- Confusing column-level with table-level permissions
- Thinking it controls schema or server access
- Assuming it controls row-level access
email of table users to user alice?Solution
Step 1: Recall PostgreSQL syntax for column-level GRANT
The correct syntax is GRANT SELECT (email) ON users TO alice; (parentheses after privilege).Step 2: Match options with syntax
GRANT SELECT(email) ON users TO alice; matches the correct syntax exactly, others misplace keywords or parentheses.Final Answer:
GRANT SELECT(email) ON users TO alice; -> Option AQuick Check:
GRANT SELECT(column) ON table TO user [OK]
- Placing column name after TO user
- Putting column inside ON table()
- Misordering keywords in the statement
employees(id, name, salary), if user bob has SELECT permission only on id and name, what will be the result of SELECT * FROM employees; executed by bob?Solution
Step 1: Understand column-level permission effect on SELECT *
User can see columns they have permission for; restricted columns appear as NULL.Step 2: Apply to given columns
Bob has permission onidandname, sosalaryshows as NULL.Final Answer:
Only id and name columns with data, salary as NULL -> Option AQuick Check:
Restricted columns show NULL, not error [OK]
- Expecting a permission denied error
- Assuming all columns show data
- Thinking restricted columns are hidden completely
GRANT SELECT ON employees(name, salary) TO carol; but get a syntax error. What is the likely cause?Solution
Step 1: Check syntax for GRANT with multiple columns
Correct syntax is GRANT SELECT (name, salary) ON employees TO carol;Step 2: Identify error in command
Command incorrectly places column list after table name; column list must follow SELECT before ON.Final Answer:
Column list in parentheses must precede the table name -> Option CQuick Check:
GRANT SELECT (col1, col2) ON table TO user [OK]
- Placing column list after table name
- Forgetting parentheses around columns
- Assuming multiple columns need separate GRANTs
dave to update only the phone column in the contacts table but not others. Which sequence of commands correctly achieves this?Solution
Step 1: Remove any existing full UPDATE permission
First revoke any broad UPDATE permission to avoid conflicts.Step 2: Grant UPDATE permission only on the phone column
Then grant UPDATE on the specific column to limit access.Final Answer:
REVOKE UPDATE ON contacts FROM dave; GRANT UPDATE(phone) ON contacts TO dave; -> Option BQuick Check:
Revoke broad then grant column-level UPDATE [OK]
- Granting column-level without revoking broad permission
- Revoking column-level instead of broad permission
- Assuming single GRANT is enough if broad permission exists
