Which of the following is the correct way to define a table partitioned by department (LIST) and sub-partitioned by joining_year (RANGE) in PostgreSQL?
easy📝 Syntax Q3 of 15
PostgreSQL - Table Partitioning
Which of the following is the correct way to define a table partitioned by department (LIST) and sub-partitioned by joining_year (RANGE) in PostgreSQL?
ACREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY LIST (joining_year) SUBPARTITION BY RANGE (department);
BCREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY RANGE (joining_year) SUBPARTITION BY LIST (department);
CCREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY HASH (department) SUBPARTITION BY LIST (joining_year);
DCREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY LIST (department) SUBPARTITION BY RANGE (joining_year);
Step-by-Step Solution
Solution:
Step 1: Identify partitioning columns and methods
The question specifies partitioning by department using LIST and sub-partitioning by joining_year using RANGE.
Step 2: Match syntax
CREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY LIST (department) SUBPARTITION BY RANGE (joining_year); correctly uses PARTITION BY LIST (department) and SUBPARTITION BY RANGE (joining_year).
Final Answer:
CREATE TABLE employees (id INT, department TEXT, joining_year INT) PARTITION BY LIST (department) SUBPARTITION BY RANGE (joining_year); is the correct syntax.
Quick Check:
Partitioning by LIST then sub-partitioning by RANGE [OK]
Quick Trick:Partition by main key, subpartition by secondary key [OK]
Common Mistakes:
Swapping partition and subpartition methods
Using unsupported partition types like HASH with subpartition
Incorrect column order in partitioning clauses
Master "Table Partitioning" in PostgreSQL
9 interactive learning modes - each teaches the same concept differently