Complete the code to create a partitioned table by range on the column 'year'.
CREATE TABLE sales (
id SERIAL PRIMARY KEY,
year INT,
amount NUMERIC
) PARTITION BY [1] (year);The PARTITION BY RANGE clause is used to partition a table based on a range of values in a column, such as 'year'.
Complete the code to create a sub-partitioned table by list on the column 'region'.
CREATE TABLE sales ( id SERIAL PRIMARY KEY, year INT, region TEXT, amount NUMERIC ) PARTITION BY range (year) SUBPARTITION BY [1] (region);
Sub-partitioning by LIST allows dividing data into discrete categories like 'region'.
Fix the error in the sub-partition creation statement by choosing the correct keyword.
CREATE TABLE sales_2023 PARTITION OF sales FOR VALUES FROM (2023) TO (2024) SUBPARTITION BY [1] (region);
The correct keyword to specify sub-partitioning is SUBPARTITION BY.
Fill both blanks to define a sub-partition for region 'north' in the 2023 sales partition.
CREATE TABLE sales_2023_north PARTITION OF sales_2023 FOR VALUES IN ([1]); ALTER TABLE sales_2023_north ADD CONSTRAINT [2] CHECK (region = 'north');
The sub-partition must specify the value 'north' and a meaningful constraint name like 'north_region_check'.
Fill all three blanks to create a sub-partitioned table with range partitioning on 'year' and hash sub-partitioning on 'month'.
CREATE TABLE sales ( id SERIAL PRIMARY KEY, year INT, month INT, amount NUMERIC ) PARTITION BY [1] (year) SUBPARTITION BY [2] (month); CREATE TABLE sales_2023 PARTITION OF sales FOR VALUES FROM (2023) TO (2024) SUBPARTITION BY [3] (month);
The main partition uses RANGE on 'year', and sub-partitioning uses HASH on 'month'.