0
0
PostgreSQLquery~5 mins

Public schema vs custom schemas in PostgreSQL - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is the public schema in PostgreSQL?
The public schema is the default schema created in every new PostgreSQL database. It is a shared space where database objects like tables and functions are stored if no other schema is specified.
Click to reveal answer
beginner
Why would you create a custom schema in PostgreSQL?
Custom schemas help organize database objects into separate namespaces. This improves clarity, security, and management by grouping related objects and avoiding name conflicts.
Click to reveal answer
intermediate
How does PostgreSQL find a table when you run a query without specifying a schema?
PostgreSQL searches schemas in the order listed in the search_path setting. By default, it looks in the public schema first, then others if configured.
Click to reveal answer
intermediate
Can multiple schemas have tables with the same name in PostgreSQL?
Yes. Schemas act like folders. Different schemas can have tables with the same name without conflict because the full name includes the schema name.
Click to reveal answer
beginner
How do you specify a table in a custom schema in a SQL query?
Use the format schema_name.table_name. For example, sales.orders refers to the orders table in the sales schema.
Click to reveal answer
What is the default schema in a new PostgreSQL database?
Acustom
Bdefault
Cmain
Dpublic
Why use custom schemas instead of only the public schema?
ATo organize objects and avoid name conflicts
BTo slow down queries
CTo delete the public schema
DTo store backups
If two schemas have a table named 'users', how does PostgreSQL know which one to use?
AIt throws an error
BIt merges both tables automatically
CIt uses the search_path order or explicit schema name
DIt always uses the public schema
How do you write a query to select from a table named 'orders' in a schema named 'sales'?
ASELECT * FROM sales.orders;
BSELECT * FROM orders.sales;
CSELECT * FROM public.orders;
DSELECT * FROM orders;
What happens if you create a table without specifying a schema in PostgreSQL?
AThe creation fails
BIt is created in the public schema by default
CIt is created in a new schema
DIt is created in the root directory
Explain the difference between the public schema and custom schemas in PostgreSQL.
Think about why you might want to separate tables into different groups.
You got /4 concepts.
    Describe how PostgreSQL uses the search_path to find tables when no schema is specified.
    Imagine looking for a file in folders one by one.
    You got /4 concepts.