CodeBlanks Logo Icon CodeBlanks

List partition

Partition by a list of values.

List partition

List partition splits by specific values. Ideal for region or category.

CREATE TABLE customers (...) PARTITION BY LIST (city);
CREATE TABLE customers_istanbul PARTITION OF customers
  FOR VALUES IN ('İstanbul');

Istanbul customers in a separate partition.

The table customers is created.

List partition — details

List partition defines a value list with FOR VALUES IN.

For example, FOR VALUES IN ('İstanbul', 'Ankara') puts rows of these two cities in one partition; a DEFAULT partition can catch values not in any list.

Practice List partition

Create the customers_istanbul partition with FOR VALUES IN ('İstanbul').

Starter code

query.sql
-- list partition
CREATE TABLE customers_istanbul PARTITION OF customers

Sample solution

query.sql
CREATE TABLE customers_istanbul PARTITION OF customers
  FOR VALUES IN ('İstanbul');

Expected output

Bölüm oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 List partition: match the terms

Term Meaning
LIST value list
FOR VALUES IN values
city region
category class

2 Add LIST

Question
PARTITION BY ____ (city)
Answer
PARTITION BY LIST (city)

Explanation: LIST partitioning splits by specific values; each city goes to its own partition.

3 What does list partition split by?

  • Specific values Correct answer
  • A hash
  • A range
  • A date

Explanation: List partition splits by specific values.

All lessons in Advanced