0
0
PostgreSQLquery~20 mins

Schema-level access control in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema Access Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this schema access query?

Consider a PostgreSQL database with a schema named sales. The user alice has been granted USAGE on the sales schema but no other privileges. What will be the result of the following query when run by alice?

SELECT * FROM sales.orders;
PostgreSQL
GRANT USAGE ON SCHEMA sales TO alice;
-- alice runs:
SELECT * FROM sales.orders;
AERROR: permission denied for relation orders
BReturns all rows from sales.orders table
CERROR: schema sales does not exist
DReturns no rows (empty result set)
Attempts:
2 left
💡 Hint

USAGE on a schema allows access to the schema itself but not to the tables inside it.

🧠 Conceptual
intermediate
1:30remaining
Which privilege is required to create tables in a schema?

In PostgreSQL, to create new tables inside an existing schema, which privilege must a user have on that schema?

AUSAGE
BINSERT
CSELECT
DCREATE
Attempts:
2 left
💡 Hint

Think about what permission allows adding new objects inside a schema.

📝 Syntax
advanced
2:00remaining
Identify the correct syntax to grant SELECT on all tables in a schema

Which of the following commands correctly grants SELECT privilege on all current tables in the inventory schema to user bob?

AGRANT SELECT ON SCHEMA inventory TO bob;
BGRANT SELECT ON ALL TABLES IN SCHEMA inventory TO bob;
CGRANT SELECT ON inventory.* TO bob;
DGRANT SELECT ON ALL TABLES inventory TO bob;
Attempts:
2 left
💡 Hint

Look for the exact phrase used in PostgreSQL to grant privileges on all tables in a schema.

optimization
advanced
2:30remaining
Best way to allow read access to all future tables in a schema

You want user carol to have SELECT access on all current and future tables in the reports schema. Which approach achieves this with minimal ongoing maintenance?

AGrant USAGE on the schema and ALTER DEFAULT PRIVILEGES to grant SELECT on future tables to carol.
BGrant SELECT on all current tables and repeat the grant manually for new tables.
CGrant CREATE on the schema to carol so she can create tables and access them.
DGrant SELECT on the schema itself.
Attempts:
2 left
💡 Hint

Think about how to automate privileges for tables created later.

🔧 Debug
expert
3:00remaining
Why does this schema-level grant not allow table access?

User dave runs the following commands:

GRANT USAGE ON SCHEMA analytics TO dave;
SELECT * FROM analytics.events;

But he gets an error: permission denied for relation events. Why?

ADave needs CONNECT privilege on the database first.
BThe schema <code>analytics</code> does not exist.
CUSAGE on schema does not grant any privileges on tables inside it.
DThe table <code>events</code> is empty, so no rows are returned.
Attempts:
2 left
💡 Hint

Consider what USAGE on a schema actually allows.