Bird
0
0

Given a partitioned table logs with partitions logs_2023 and logs_2024, what will be the result of this command?

medium📝 query result Q4 of 15
PostgreSQL - Table Partitioning
Given a partitioned table logs with partitions logs_2023 and logs_2024, what will be the result of this command?

ALTER TABLE logs DETACH PARTITION logs_2023;

Then querying SELECT count(*) FROM logs;
ACount of rows only from logs_2024 partition
BCount of rows from both logs_2023 and logs_2024 partitions
CError because logs_2023 is detached
DCount of rows only from logs_2023 partition
Step-by-Step Solution
Solution:
  1. Step 1: Understand DETACH PARTITION effect

    Detaching removes the partition from the partitioned table but keeps the data in the detached table.
  2. Step 2: Query behavior after detach

    Querying the partitioned table counts rows only in attached partitions, so logs_2023 rows are excluded.
  3. Final Answer:

    Count of rows only from logs_2024 partition -> Option A
  4. Quick Check:

    Detached partition excluded from queries = Count of rows only from logs_2024 partition [OK]
Quick Trick: Detached partitions are excluded from partitioned table queries [OK]
Common Mistakes:
  • Assuming detached partitions still count in queries
  • Expecting an error after detach
  • Confusing detach with drop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes