0
0
PostgreSQLquery~20 mins

Column-level permissions in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Column-level Permissions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What columns can user 'report_viewer' select from 'sales'?

Given the following permissions:

GRANT SELECT (date, amount) ON sales TO report_viewer;

Which columns will be visible to report_viewer when running SELECT * FROM sales;?

PostgreSQL
SELECT * FROM sales;
AAll columns from 'sales' are returned regardless of column-level permissions.
BOnly columns 'date' and 'amount' are returned; other columns are hidden.
CNo columns are returned; query fails with permission error.
DOnly columns 'date' and 'amount' are returned, but other columns show NULL values.
Attempts:
2 left
💡 Hint

Think about how PostgreSQL enforces column-level SELECT permissions.

🧠 Conceptual
intermediate
2:00remaining
What happens if a user lacks SELECT permission on a column?

If a user has SELECT permission on a table but is denied SELECT on one column, what happens when they query that column?

AThe query returns zero rows.
BThe query returns the actual data for that column anyway.
CThe query fails with a permission denied error.
DThe query returns NULL for that column without error.
Attempts:
2 left
💡 Hint

Consider how PostgreSQL enforces column-level security strictly.

📝 Syntax
advanced
2:00remaining
Which statement correctly grants SELECT on specific columns?

Choose the correct SQL statement to grant SELECT permission on columns 'name' and 'email' of table 'customers' to user 'client_user'.

AGRANT SELECT ON customers(name, email) TO client_user;
BGRANT SELECT (name, email) ON customers TO client_user;
CGRANT SELECT ON customers TO client_user (name, email);
DGRANT SELECT TO client_user ON customers(name, email);
Attempts:
2 left
💡 Hint

Remember the syntax order for column-level grants in PostgreSQL.

optimization
advanced
2:00remaining
How to optimize queries with column-level permissions for performance?

You have a table with many columns but users have SELECT permission on only a few columns. What is the best way to optimize query performance for these users?

ACreate a view with only the allowed columns and grant SELECT on the view instead of the base table.
BGrant SELECT on all columns but filter results in application code.
CUse SELECT * queries and rely on PostgreSQL to filter columns internally.
DCreate a trigger to hide unauthorized columns at query time.
Attempts:
2 left
💡 Hint

Think about how views can simplify permissions and improve query speed.

🔧 Debug
expert
2:00remaining
Why does this query fail despite column-level SELECT grant?

User 'analyst' has been granted SELECT on columns 'id' and 'score' of table 'results'. The following query fails with permission denied error:

SELECT id, score, comments FROM results;

Why does this happen?

AUser lacks SELECT permission on column 'comments', causing the entire query to fail.
BUser must have SELECT on all columns in the table to run any SELECT query.
CThe query syntax is invalid because 'comments' is not included in the grant.
DPostgreSQL does not support column-level permissions on SELECT statements.
Attempts:
2 left
💡 Hint

Check which columns the user is allowed to select and which are requested.