Bird
0
0

You try to create a partition for a range partitioned table by date with this command:

medium📝 Debug Q14 of 15
PostgreSQL - Table Partitioning
You try to create a partition for a range partitioned table by date with this command:
CREATE TABLE sales_2025 PARTITION OF sales FOR VALUES FROM ('2025-01-01') TO ('2024-12-31');

What is the problem with this statement?
AThe TO date is earlier than the FROM date, causing a range error
BPartition names cannot contain numbers
CYou must specify LIST partitioning, not RANGE
DThe sales table must be dropped before adding partitions
Step-by-Step Solution
Solution:
  1. Step 1: Check the FROM and TO values in partition definition

    The TO value '2024-12-31' is before the FROM value '2025-01-01', which is invalid for range partitions.
  2. Step 2: Understand partition range rules

    Range partitions require FROM value to be less than TO value to define a valid range.
  3. Final Answer:

    The TO date is earlier than the FROM date, causing a range error -> Option A
  4. Quick Check:

    FROM must be less than TO in range partitions [OK]
Quick Trick: FROM date must be before TO date in range partitions [OK]
Common Mistakes:
  • Swapping FROM and TO dates
  • Thinking partition names cannot have numbers
  • Confusing range with list partitioning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes