ClickHouse/docs/en/sql-reference/statements/alter/sample-by.md

34 lines
1.1 KiB
Markdown
Raw Normal View History

2020-08-27 13:10:10 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/statements/alter/sample-by
sidebar_position: 41
sidebar_label: SAMPLE BY
2022-08-29 16:19:50 +00:00
title: "Manipulating Sampling-Key Expressions"
2020-08-27 13:10:10 +00:00
---
2023-07-09 12:38:16 +00:00
# Manipulating SAMPLE BY expression
The following operations are available:
## MODIFY
2020-08-27 13:10:10 +00:00
``` sql
ALTER TABLE [db].name [ON CLUSTER cluster] MODIFY SAMPLE BY new_expression
```
2023-07-09 12:38:16 +00:00
The command changes the [sampling key](../../../engines/table-engines/mergetree-family/mergetree.md) of the table to `new_expression` (an expression or a tuple of expressions). The primary key must contain the new sample key.
## REMOVE
``` sql
ALTER TABLE [db].name [ON CLUSTER cluster] REMOVE SAMPLE BY
```
The command removes the [sampling key](../../../engines/table-engines/mergetree-family/mergetree.md) of the table.
2020-08-27 13:10:10 +00:00
2023-07-09 12:38:16 +00:00
The commands `MODIFY` and `REMOVE` are lightweight in the sense that they only change metadata or remove files.
2020-08-27 13:10:10 +00:00
:::note
It only works for tables in the [MergeTree](../../../engines/table-engines/mergetree-family/mergetree.md) family (including [replicated](../../../engines/table-engines/mergetree-family/replication.md) tables).
2022-08-29 16:19:50 +00:00
:::