Skip to content

Instantly share code, notes, and snippets.

@SantjagoCorkez
Last active November 13, 2020 02:43
Show Gist options
  • Save SantjagoCorkez/a3444b9ada791e90337af600915ff8dc to your computer and use it in GitHub Desktop.
Save SantjagoCorkez/a3444b9ada791e90337af600915ff8dc to your computer and use it in GitHub Desktop.
create table tbl (
part_key1 int,
part_key2 int,
part_key3 int,
part_key4 int,
values_columns varchar
) partition by list(part_key1);
create table tbl_p1 partition of tbl for values in (1) partition by list(part_key2);
create table tbl_p1_p2 partition of tbl_p1 for values in (1) partition by range (part_key3);
create table tbl_p1_p2_p3 partition of tbl_p1_p2 (constraint tbl_p1_p2_p3_pkey primary key (part_key3, part_key4)) for values from (0) to (100) partition by HASH(part_key4);
create table tbl_p1_p2_p3_p4_0 partition of tbl_p1_p2_p3 for values with (modulus 4, remainder 0);
create table tbl_p1_p2_p3_p4_1 partition of tbl_p1_p2_p3 for values with (modulus 4, remainder 1);
create table tbl_p1_p2_p3_p4_2 partition of tbl_p1_p2_p3 for values with (modulus 4, remainder 2);
create table tbl_p1_p2_p3_p4_3 partition of tbl_p1_p2_p3 for values with (modulus 4, remainder 3);
insert into tbl values (1, 1, 1, 1, 'a');
insert into tbl values (1, 1, 1, 1, 'a');
-- ERROR: duplicate key value violates unique constraint "tbl_p1_p2_p3_p4_0_pkey"
-- DETAIL: Key (part_key3, part_key4)=(1, 1) already exists.
insert into tbl values (1, 1, 1, 1, 'b') on conflict (part_key3, part_key4) do update set values_columns = excluded.values_columns;
-- ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment