Complete the code to create a partitioned table by specifying the partition method.
CREATE TABLE sales_data (id INT, sale_date DATE, amount NUMERIC) PARTITION BY [1] (sale_date);The RANGE partition method divides data into ranges, which is common for date columns like sale_date.
Complete the code to create a partition for sales_data for the year 2023.
CREATE TABLE sales_2023 PARTITION OF sales_data FOR VALUES FROM ('2023-01-01') TO ([1]);
The upper bound for the partition should be the start of the next range, so '2024-01-01' is correct.
Complete the code to create a partition for sales_data for the year 2024.
CREATE TABLE sales_2024 PARTITION OF sales_data FOR VALUES FROM ('2024-01-01') TO ([1]);
The upper bound for the partition should be the start of the next range, so '2025-01-01' is correct.
Fill both blanks to complete the query that selects sales data only from the 2023 partition.
SELECT * FROM sales_data WHERE sale_date [1] '2023-01-01' AND sale_date [2] '2024-01-01';
<= for the upper bound which includes the next year.< for the lower bound which excludes the first day.The query selects sales from January 1, 2023 (inclusive) up to but not including January 1, 2024, so use >= and <.
Fill all three blanks to create a partitioned table by list and add a partition for region 'North'.
CREATE TABLE customer_data (id INT, region TEXT) PARTITION BY [1] (region); CREATE TABLE customer_north PARTITION OF customer_data FOR VALUES IN ([2]); INSERT INTO customer_north (id, region) VALUES (1, [3]);
List partitioning is used for discrete values like regions. The partition is created for the value 'North', and the insert uses the same string.