Bird
0
0

Consider the following setup:

medium📝 query result Q4 of 15
PostgreSQL - Table Partitioning
Consider the following setup:
CREATE TABLE inventory (item_id INT, restock_date DATE) PARTITION BY RANGE (restock_date);
CREATE TABLE inventory_2024 PARTITION OF inventory FOR VALUES FROM ('2024-01-01') TO ('2025-01-01');
INSERT INTO inventory VALUES (100, '2024-07-20');
SELECT * FROM inventory_2024;

What will be the result of the SELECT query?
AIt will return the row with item_id 100 and restock_date '2024-07-20'.
BIt will return no rows because the partition range is incorrect.
CIt will cause an error because the partition does not exist.
DIt will return all rows from the inventory table.
Step-by-Step Solution
Solution:
  1. Step 1: Understand partition range

    The partition inventory_2024 covers dates from '2024-01-01' inclusive to '2025-01-01' exclusive.
  2. Step 2: Check inserted row date

    The inserted row has restock_date = '2024-07-20', which falls within the partition range.
  3. Step 3: Query partition table

    Selecting from inventory_2024 will return the inserted row.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Row date within partition range means it is stored and retrievable from that partition [OK]
Quick Trick: Rows with dates inside partition range appear in that partition [OK]
Common Mistakes:
  • Assuming TO value is inclusive
  • Thinking partition tables are empty until queried
  • Confusing partition table with parent table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes