Bird
0
0

Which of the following commands correctly creates a hash partitioned table products partitioned by product_id in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Table Partitioning
Which of the following commands correctly creates a hash partitioned table products partitioned by product_id in PostgreSQL?
ACREATE TABLE products (product_id INT, name TEXT) PARTITION BY HASH (product_id);
BCREATE TABLE products PARTITION BY HASH (product_id) (product_id INT, name TEXT);
CCREATE TABLE products (product_id INT, name TEXT) PARTITION BY RANGE (product_id);
DCREATE TABLE products (product_id INT, name TEXT) PARTITION BY LIST (product_id);
Step-by-Step Solution
Solution:
  1. Step 1: Identify partitioning method

    The question requires hash partitioning on product_id.
  2. Step 2: Check syntax correctness

    CREATE TABLE products (product_id INT, name TEXT) PARTITION BY HASH (product_id); uses correct syntax: PARTITION BY HASH (product_id) after table columns.
  3. Step 3: Eliminate incorrect options

    CREATE TABLE products PARTITION BY HASH (product_id) (product_id INT, name TEXT); has incorrect syntax order; Options C and D use different partitioning methods (RANGE, LIST).
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Correct syntax places PARTITION BY HASH after column definitions [OK]
Quick Trick: Use PARTITION BY HASH after columns [OK]
Common Mistakes:
  • Placing PARTITION BY before column definitions
  • Using RANGE or LIST instead of HASH
  • Incorrect syntax order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes