CLUSTER BY

CLUSTER BY can be used to change clustering keys in a table.

Read our Data clustering guide for more information.

See also: DROP CLUSTERING KEY, CREATE TABLE.

Permissions

The role must have the DDL permission at the database or table level.

Syntax

alter_table_rename_table_statement ::=
    ALTER TABLE [schema_name.]table_name CLUSTER BY column_name [, ...]
    ;

table_name ::= identifier

column_name ::= identifier

Parameters

Parameter Description
schema_name The schema name for the table. Defaults to public if not specified.
table_name The table name to apply the change to.
column_name [, ... ] Comma separated list of columns to create clustering keys for

Usage notes

Removing clustering keys does not affect existing data.

To force data to re-cluster, the table has to be recreated (i.e. with CREATE TABLE AS).

Examples

Reclustering a table

ALTER TABLE public.users CLUSTER BY start_date;