Challenge - 5 Problems
Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Purpose of the public schema in PostgreSQL
What is the main purpose of the public schema in a PostgreSQL database?
Attempts:
2 left
💡 Hint
Think about what happens when you create a table without specifying a schema.
✗ Incorrect
The public schema is the default schema in PostgreSQL. When you create tables without specifying a schema, they go into public. It is accessible by all users by default.
❓ query_result
intermediate2:00remaining
Querying tables in custom schemas
Given two schemas,
Assume the search_path is set to
public and sales, both containing a table named customers, what will the following query return?SELECT * FROM customers;
Assume the search_path is set to
"sales", public.Attempts:
2 left
💡 Hint
Check the order of schemas in the search_path and how PostgreSQL resolves table names.
✗ Incorrect
PostgreSQL searches schemas in the order listed in search_path. Since 'sales' is first, it finds sales.customers and returns its rows.
📝 Syntax
advanced2:00remaining
Creating a table in a custom schema
Which of the following SQL statements correctly creates a table named
orders inside a custom schema called inventory?Attempts:
2 left
💡 Hint
Remember the syntax to specify schema when creating a table.
✗ Incorrect
To create a table in a specific schema, prefix the table name with the schema name and a dot. Options C and D use invalid syntax.
❓ optimization
advanced2:00remaining
Improving query performance with schemas
You have multiple schemas with tables named
transactions. To optimize queries, which approach is best when you want to avoid scanning unnecessary tables?Attempts:
2 left
💡 Hint
Think about how PostgreSQL resolves table names and how specifying schema affects query plans.
✗ Incorrect
Specifying schema explicitly avoids ambiguity and ensures the query planner targets the correct table, improving performance.
🔧 Debug
expert3:00remaining
Resolving permission errors with custom schemas
A user tries to query a table
inventory.products but gets a permission denied error. The user can query public.products fine. What is the most likely cause?Attempts:
2 left
💡 Hint
Remember that schema permissions control access to objects inside them.
✗ Incorrect
In PostgreSQL, users need USAGE privilege on a schema to access objects inside it, even if they have privileges on the tables.