Complete the code to create a range partitioned table by year.
CREATE TABLE sales (
id SERIAL PRIMARY KEY,
sale_date DATE NOT NULL,
amount NUMERIC
) PARTITION BY [1] (sale_date);The range partition type divides data into ranges of values, such as dates or numbers.
Complete the code to create a list partitioned table by region.
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
region TEXT NOT NULL
) PARTITION BY [1] (region);The list partition type divides data by specific values, such as regions or categories.
Fix the error in the partition creation statement for hash partitioning.
CREATE TABLE logs (
id SERIAL PRIMARY KEY,
event_time TIMESTAMP NOT NULL,
message TEXT
) PARTITION BY [1] (id);The hash partition type distributes rows evenly across partitions based on a hash of the partition key.
Fill both blanks to create a range partition for sales in 2023.
CREATE TABLE sales_2023 PARTITION OF sales FOR VALUES FROM ([1]) TO ([2]);
Range partitions specify a start (inclusive) and end (exclusive) value. For 2023, start is '2023-01-01' and end is '2024-01-01'.
Fill all three blanks to create a list partition for customers from 'North', 'East', and 'West' regions.
CREATE TABLE customers_north_east PARTITION OF customers FOR VALUES IN ([1], [2], [3]);
List partitions specify exact values. Here, we include 'North', 'East', and 'West' regions in the partition.