PostgreSQL PARTITION BY HASH
PostgreSQL PARTITION BY HASH is a SQL statement in the PostgreSQL Specific category. PostgreSQL 11+: hash partitioning distributes rows evenly across partitions based on a hash of the key. The syntax is CREATE TABLE t (columns) PARTITION BY HASH (column);. It returns hash-partitioned table. A typical example: CREATE TABLE orders_hash ( id INT, customer_id INT, order_date DATE, amount DECIMAL ) PARTITION BY HASH (customer_id); CREATE TABLE orders_hash_0 PARTITION OF orders_hash FOR VALUES WITH (MODULUS 4, REMAINDER 0); CREATE TABLE orders_hash_1 PARTITION OF orders_hash FOR VALUES WITH (MODULUS 4, REMAINDER 1); CREATE TABLE orders_hash_2 PARTITION OF orders_hash FOR VALUES WITH (MODULUS 4, REMAINDER 2); CREATE TABLE orders_hash_3 PARTITION OF orders_hash FOR VALUES WITH (MODULUS 4, REMAINDER 3); --… A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server).