-- WITHOUT partitioning

CREATE TABLE case_test (
        d1 INTEGER,
        d2 INTEGER
);

INSERT INTO case_test
SELECT
(
        SELECT x
        FROM (
                SELECT floor(random() * 3)
                FROM generate_series(1, 1 + b * 0) AS v(x)
        ) AS z2(x)
),
(
        SELECT x
        FROM (
                SELECT floor(random() * 3)
                FROM generate_series(1, 1 + b * 0) AS v(x)
        ) AS z2(x)
)
FROM generate_series(1,100000) as a(b);

SELECT * FROM case_test LIMIT 10;

-- WITH partitioning

CREATE TABLE case_test2 (
        d1 INTEGER,
        d2 INTEGER
)
PARTITION BY LIST (d1);

CREATE TABLE case_test2_0
PARTITION OF case_test2
FOR VALUES IN (0);

CREATE TABLE case_test2_1
PARTITION OF case_test2
FOR VALUES IN (1);

CREATE TABLE case_test2_2
PARTITION OF case_test2
FOR VALUES IN (2);

CREATE TABLE case_test2_3
PARTITION OF case_test2
FOR VALUES IN (3);

INSERT INTO case_test2
SELECT
(
        SELECT x
        FROM (
                SELECT floor(random() * 3)
                FROM generate_series(1, 1 + b * 0) AS v(x)
        ) AS z2(x)
),
(
        SELECT x
        FROM (
                SELECT floor(random() * 3)
                FROM generate_series(1, 1 + b * 0) AS v(x)
        ) AS z2(x)
)
FROM generate_series(1,100000) as a(b);

SELECT * FROM case_test2 LIMIT 10;
