Bird
0
0

You have a large sales table partitioned by month using range partitioning on sale_date. You want to add a new partition for March 2024. Which of the following commands correctly adds this partition?

hard📝 Application Q15 of 15
PostgreSQL - Table Partitioning
You have a large sales table partitioned by month using range partitioning on sale_date. You want to add a new partition for March 2024. Which of the following commands correctly adds this partition?
ACREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-03-01') TO ('2024-03-31');
BCREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-02-28') TO ('2024-03-31');
CCREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-03-01') TO ('2024-04-01');
DCREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-03-01') TO ('2024-03-30');
Step-by-Step Solution
Solution:
  1. Step 1: Understand range partition boundaries for months

    Range partitions use inclusive FROM and exclusive TO, so March 2024 is from '2024-03-01' up to but not including '2024-04-01'.
  2. Step 2: Check each option's date range correctness

    CREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-03-01') TO ('2024-04-01'); correctly uses FROM '2024-03-01' TO '2024-04-01'. Options B, C, and D have incorrect boundaries that either overlap or exclude days.
  3. Final Answer:

    CREATE TABLE sales_2024_03 PARTITION OF sales FOR VALUES FROM ('2024-03-01') TO ('2024-04-01'); -> Option C
  4. Quick Check:

    Range partitions: FROM inclusive, TO exclusive [OK]
Quick Trick: Use TO date as first day of next month for monthly partitions [OK]
Common Mistakes:
  • Using TO date as last day of month (should be exclusive)
  • Overlapping partition ranges
  • Using incorrect FROM dates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes