Bird
0
0

Which of the following is the correct syntax to create a range partitioned table in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Table Partitioning
Which of the following is the correct syntax to create a range partitioned table in PostgreSQL?
ACREATE TABLE sales PARTITION BY RANGE (sale_date) (id INT, sale_date DATE);
BCREATE TABLE sales (id INT, sale_date DATE) PARTITION BY RANGE (sale_date);
CCREATE TABLE sales (id INT, sale_date DATE) PARTITION BY LIST (sale_date);
DCREATE TABLE sales (id INT, sale_date DATE) PARTITION ON RANGE (sale_date);
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct partition syntax

    PostgreSQL uses PARTITION BY RANGE (column) after table columns in CREATE TABLE.
  2. Step 2: Check options

    CREATE TABLE sales (id INT, sale_date DATE) PARTITION BY RANGE (sale_date); matches correct syntax. CREATE TABLE sales PARTITION BY RANGE (sale_date) (id INT, sale_date DATE); misplaces PARTITION BY clause. CREATE TABLE sales (id INT, sale_date DATE) PARTITION BY LIST (sale_date); uses LIST instead of RANGE. CREATE TABLE sales (id INT, sale_date DATE) PARTITION ON RANGE (sale_date); uses incorrect keyword PARTITION ON.
  3. Final Answer:

    CREATE TABLE sales (id INT, sale_date DATE) PARTITION BY RANGE (sale_date); -> Option B
  4. Quick Check:

    Correct partition syntax = CREATE TABLE sales (id INT, sale_date DATE) PARTITION BY RANGE (sale_date); [OK]
Quick Trick: PARTITION BY clause goes after columns in CREATE TABLE [OK]
Common Mistakes:
  • Placing PARTITION BY before columns
  • Using PARTITION ON instead of PARTITION BY
  • Confusing RANGE with LIST partitioning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes