CLUSTER BY
The CLUSTER BY
command is used for changing clustering keys in a table.
For more information, see DROP CLUSTERING KEY, CREATE TABLE
Syntax
ALTER TABLE [schema_name.]table_name CLUSTER BY column_name [, ...]
create_table_statement ::=
CREATE [ OR REPLACE ] TABLE [schema_name.]table_name (
{ column_def [, ...] }
)
[ CLUSTER BY { column_name [, ...] } ]
column_def :: = { column_name type_name [ default ] [ column_constraint ] }
table_name ::= identifier
column_name ::= identifier
Parameters
Parameter |
Description |
---|---|
|
The schema name for the table. Defaults to |
|
Creates a new tables and overwrites any existing table by the same name. Does not return an error if the table already exists. |
|
A comma separated list of column definitions. A minimal column definition includes a name identifier and a datatype. Other column constraints and default values can be added optionally |
|
The table name to apply the change to |
|
Comma separated list of columns to create clustering keys for |
Usage Notes
Clustering by
TEXT
columns is not supportedRemoving clustering keys does not affect existing data
To force data to re-cluster, the table has to be recreated (i.e. with CREATE TABLE).
Example
Reclustering a Table
ALTER TABLE
public.users CLUSTER BY start_date;
Permissions
The role must have the DDL
permission at the database or table level.