0
0
PostgreSQLquery~20 mins

Public schema vs custom schemas in PostgreSQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Schema Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of the public schema in PostgreSQL
What is the main purpose of the public schema in a PostgreSQL database?
AIt is used only for temporary tables that disappear after the session ends.
BIt is a special schema that stores system tables and cannot be modified by users.
CIt is the default schema where all users can create and access tables unless specified otherwise.
DIt is a schema that automatically encrypts all data stored within it.
Attempts:
2 left
💡 Hint
Think about what happens when you create a table without specifying a schema.
query_result
intermediate
2:00remaining
Querying tables in custom schemas
Given two schemas, 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.
ARows from the <code>sales.customers</code> table.
BRows from the <code>public.customers</code> table.
CAn error because the table name is ambiguous.
DNo rows because the query does not specify a schema.
Attempts:
2 left
💡 Hint
Check the order of schemas in the search_path and how PostgreSQL resolves table names.
📝 Syntax
advanced
2: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?
ACREATE TABLE orders.inventory (id SERIAL PRIMARY KEY, product TEXT);
BCREATE TABLE orders (id SERIAL PRIMARY KEY, product TEXT) SET SCHEMA inventory;
CCREATE TABLE orders (id SERIAL PRIMARY KEY, product TEXT) IN SCHEMA inventory;
DCREATE TABLE inventory.orders (id SERIAL PRIMARY KEY, product TEXT);
Attempts:
2 left
💡 Hint
Remember the syntax to specify schema when creating a table.
optimization
advanced
2: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?
ACreate views in the public schema that join all <code>transactions</code> tables from different schemas.
BAlways specify the schema explicitly in queries to target the correct table.
CKeep all tables named <code>transactions</code> in the public schema and rely on search_path.
DUse temporary tables instead of schemas to separate data.
Attempts:
2 left
💡 Hint
Think about how PostgreSQL resolves table names and how specifying schema affects query plans.
🔧 Debug
expert
3: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?
AThe user lacks USAGE privilege on the <code>inventory</code> schema.
BThe table <code>inventory.products</code> does not exist.
CThe user has no SELECT privilege on <code>public.products</code>.
DThe search_path does not include <code>inventory</code> schema.
Attempts:
2 left
💡 Hint
Remember that schema permissions control access to objects inside them.