Complete the code to create a partitioned table by date.
CREATE TABLE sales (id SERIAL PRIMARY KEY, sale_date DATE, amount NUMERIC) PARTITION BY [1] (sale_date);Range partitioning is used to divide data based on ranges of values, such as dates.
Complete the code to create a partition for sales in 2023.
CREATE TABLE sales_2023 PARTITION OF sales FOR VALUES FROM ('2023-01-01') [1] ('2024-01-01');
The syntax uses FOR VALUES FROM ... TO ... where TO specifies the exclusive upper bound.
Fix the error in the partition creation by completing the missing keyword.
CREATE TABLE sales_q1_2023 PARTITION OF sales FOR VALUES [1] ('2023-01-01') TO ('2023-04-01');
The correct syntax is FOR VALUES FROM (start) TO (end) for range partitions.
Fill both blanks to create a partition for sales in the first half of 2024.
CREATE TABLE sales_h1_2024 PARTITION OF sales FOR VALUES [1] ('2024-01-01') [2] ('2024-07-01');
Range partitions use FROM and TO to specify the start and end of the range.
Fill both blanks to create a partition for sales in July 2024.
CREATE TABLE sales_july_2024 PARTITION OF sales FOR VALUES [1] ('2024-07-01') [2] ('2024-08-01');
The syntax uses FROM and TO to define the range, and TO is exclusive by default.
