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:
Step 1: Recall correct partition syntax
PostgreSQL uses PARTITION BY RANGE (column) after table columns in CREATE TABLE.
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.
Final Answer:
CREATE TABLE sales (id INT, sale_date DATE) PARTITION BY RANGE (sale_date); -> Option B
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
Master "Table Partitioning" in PostgreSQL
9 interactive learning modes - each teaches the same concept differently