2

I'm setting up a partitioned by hash table in PostgreSQL 12 which will have 256 partitions. I'm using uuid as my primary key for the table. Is it acceptable to use the same uuid column as the hash key?

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
david
  • 997
  • 3
  • 14
  • 34

1 Answers1

0

Not only acceptable, but required.

Per the docs, 11.6. Unique Indexes

"PostgreSQL automatically creates a unique index when a unique constraint or primary key is defined for a table. The index covers the columns that make up the primary key or unique constraint (a multicolumn index, if appropriate), and is the mechanism that enforces the constraint."

Also per the docs, 5.11.2.3. Limitations,

The following limitations apply to partitioned tables:

"Unique constraints on partitioned tables must include all the partition key columns. This limitation exists because PostgreSQL can only enforce uniqueness in each partition individually."

cse
  • 1
  • 1