Bird
0
0

Consider a PostgreSQL table partitioned by RANGE on a column 'event_date' with partitions for years 2022 and 2023 only. What occurs if you insert a row with event_date = '2024-05-10'?

medium📝 query result Q4 of 15
PostgreSQL - Table Partitioning
Consider a PostgreSQL table partitioned by RANGE on a column 'event_date' with partitions for years 2022 and 2023 only. What occurs if you insert a row with event_date = '2024-05-10'?
APostgreSQL creates a new partition for 2024 automatically
BThe row is automatically placed in the 2023 partition
CThe insert fails with an error due to missing partition for 2024
DThe row is inserted into a default partition if it exists
Step-by-Step Solution
Solution:
  1. Step 1: Understand range partitions

    Range partitions require explicit partitions covering the inserted value's range.
  2. Step 2: Check partition coverage

    Since partitions exist only for 2022 and 2023, no partition covers 2024-05-10.
  3. Step 3: Result of insert

    Without a matching partition or default partition, PostgreSQL raises an error on insert.
  4. Final Answer:

    The insert fails with an error due to missing partition for 2024 -> Option C
  5. Quick Check:

    Missing partition causes insert failure [OK]
Quick Trick: Range partitions must cover all inserted values [OK]
Common Mistakes:
  • Assuming PostgreSQL auto-creates missing partitions
  • Believing rows go to nearest existing partition
  • Forgetting default partition can catch unmatched rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes