0
0
PostgreSQLquery~20 mins

List partitioning by category in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
List Partitioning Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of inserting data into a category partitioned table

Given a PostgreSQL table products partitioned by LIST on the category column, what will be the output of the following query?

INSERT INTO products (id, name, category) VALUES (1, 'Apple', 'Fruit') RETURNING *;

Assume partitions exist for categories 'Fruit' and 'Vegetable'.

PostgreSQL
CREATE TABLE products (id INT, name TEXT, category TEXT) PARTITION BY LIST (category);
CREATE TABLE products_fruit PARTITION OF products FOR VALUES IN ('Fruit');
CREATE TABLE products_vegetable PARTITION OF products FOR VALUES IN ('Vegetable');
A1 | Apple | NULL
BError: no partition for category 'Fruit'
C1 | Apple | Fruit
D1 | Apple | Vegetable
Attempts:
2 left
💡 Hint

Check if the partition for the category exists before inserting.

🧠 Conceptual
intermediate
1:30remaining
Understanding list partitioning behavior

Which statement best describes how PostgreSQL routes data when using LIST partitioning by category?

AData is routed randomly to any partition regardless of the key value.
BData is routed to partitions based on matching the partition key value exactly in the partition's value list.
CData is routed to partitions based on range intervals of the key value.
DData is routed to the default partition only.
Attempts:
2 left
💡 Hint

Think about how LIST partitioning differs from RANGE partitioning.

📝 Syntax
advanced
2:30remaining
Correct syntax for creating a list partitioned table

Which of the following SQL statements correctly creates a table orders partitioned by LIST on the order_type column with partitions for 'Online' and 'InStore'?

A
CREATE TABLE orders (id INT, order_type TEXT) PARTITION BY LIST (order_type);
CREATE TABLE orders_online PARTITION OF orders FOR VALUES IN ('Online');
CREATE TABLE orders_instore PARTITION OF orders FOR VALUES IN ('InStore');
B
CREATE TABLE orders (id INT, order_type TEXT) PARTITION BY RANGE (order_type);
CREATE TABLE orders_online PARTITION OF orders FOR VALUES IN ('Online');
CREATE TABLE orders_instore PARTITION OF orders FOR VALUES IN ('InStore');
C
CREATE TABLE orders (id INT, order_type TEXT) PARTITION BY LIST (order_type);
CREATE TABLE orders_online PARTITION OF orders FOR VALUES FROM ('Online') TO ('Online');
CREATE TABLE orders_instore PARTITION OF orders FOR VALUES FROM ('InStore') TO ('InStore');
D
CREATE TABLE orders (id INT, order_type TEXT) PARTITION BY LIST (order_type);
CREATE TABLE orders_online PARTITION OF orders FOR VALUES IN ('Online', 'InStore');
Attempts:
2 left
💡 Hint

Check the partitioning method and the syntax for partition value lists.

optimization
advanced
2:00remaining
Optimizing queries on list partitioned tables

You have a large sales table partitioned by LIST on region. Which query will most efficiently use partition pruning to scan only the 'North' region partition?

ASELECT * FROM sales WHERE region <> 'North';
BSELECT * FROM sales WHERE region LIKE '%North%';
CSELECT * FROM sales WHERE region IN ('North', 'South');
DSELECT * FROM sales WHERE region = 'North';
Attempts:
2 left
💡 Hint

Partition pruning works best with exact matches on the partition key.

🔧 Debug
expert
3:00remaining
Diagnosing insert failure on list partitioned table

Given a table employees partitioned by LIST on department with partitions for 'HR' and 'IT', the following insert fails:

INSERT INTO employees (id, name, department) VALUES (10, 'John Doe', 'Finance');

What is the most likely cause of this error?

ANo partition exists for the 'Finance' department, so the insert fails.
BThe 'Finance' value is misspelled in the insert statement.
CThe table is partitioned by RANGE, not LIST, causing the error.
DThe 'department' column is missing from the table definition.
Attempts:
2 left
💡 Hint

Check if a partition exists for the inserted category value.