-
Notifications
You must be signed in to change notification settings - Fork 130
Alter hypertable update for drop column/change type #4584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
atovpeko
merged 4 commits into
latest
from
3791-feedback-feedback-page-use-timescalelatesthypertablesalter
Nov 24, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ import CreateHypertablePolicyNote from "versionContent/_partials/_create-hyperta | |
|
|
||
| # Optimize time-series data in hypertables | ||
|
|
||
| Hypertables are designed for real-time analytics, they are $PG tables that automatically partition your data by | ||
| time. Typically, you partition hypertables on columns that hold time values. | ||
| $HYPERTABLE_CAP are designed for real-time analytics, they are $PG tables that automatically partition your data by | ||
| time. Typically, you partition $HYPERTABLE on columns that hold time values. | ||
| [Best practice is to use `timestamptz`][timestamps-best-practice] column type. However, you can also partition on | ||
| `date`, `integer`, `timestamp` and [UUIDv7][uuidv7_functions] types. | ||
|
|
||
|
|
@@ -53,14 +53,13 @@ To convert an existing table with data in it, call `create_hypertable` on that t | |
|
|
||
| ## Alter a hypertable | ||
|
|
||
| You can alter a hypertable, for example to add a column, by using the $PG | ||
| [`ALTER TABLE`][postgres-altertable] command. This works for both regular and | ||
| distributed hypertables. | ||
| You can alter a $HYPERTABLE, for example to add a column, by using the $PG | ||
| [`ALTER TABLE`][postgres-altertable] command. Some operations are not supported for $HYPERTABLE with $COLUMNSTORE enabled. See [Altering $HYPERTABLEs with $COLUMNSTORE enabled][alter-schema]. | ||
|
|
||
| ### Add a column to a hypertable | ||
|
|
||
| You add a column to a hypertable using the `ALTER TABLE` command. In this | ||
| example, the hypertable is named `conditions` and the new column is named | ||
| You add a column to a $HYPERTABLE using the `ALTER TABLE` command. In this | ||
| example, the $HYPERTABLE is named `conditions` and the new column is named | ||
| `humidity`: | ||
|
|
||
| ```sql | ||
|
|
@@ -71,34 +70,64 @@ ALTER TABLE conditions | |
| If the column you are adding has the default value set to `NULL`, or has no | ||
| default value, then adding a column is relatively fast. If you set the default | ||
| to a non-null value, it takes longer, because it needs to fill in this value for | ||
| all existing rows of all existing chunks. | ||
| all existing rows of all existing $CHUNKs. | ||
|
|
||
| ### Rename a hypertable | ||
|
|
||
| You can change the name of a hypertable using the `ALTER TABLE` command. In this | ||
| example, the hypertable is called `conditions`, and is being changed to the new | ||
| You can change the name of a $HYPERTABLE using the `ALTER TABLE` command. In this | ||
| example, the $HYPERTABLE is called `conditions`, and is being changed to the new | ||
| name, `weather`: | ||
|
|
||
| ```sql | ||
| ALTER TABLE conditions | ||
| RENAME TO weather; | ||
| ``` | ||
|
|
||
| ### Change a column data type | ||
|
|
||
| You can change the data type of a column in a $HYPERTABLE using the `ALTER TABLE` | ||
| command. In this example, the `temperature` column data type is changed from `DOUBLE PRECISION` | ||
| to `NUMERIC`: | ||
|
|
||
| ```sql | ||
| ALTER TABLE conditions | ||
| ALTER COLUMN temperature TYPE NUMERIC; | ||
| ``` | ||
|
|
||
| The following restrictions apply: | ||
|
|
||
| - You cannot change the type of `segmentby` columns. | ||
| - For time dimension columns, you can only change to `TIMESTAMPTZ`, `TIMESTAMP`, `DATE`, | ||
| `INTEGER` (smallint, integer, or bigint), or `UUID` (UUIDv7 only). | ||
| - You cannot change the type of columns with custom partitioning functions. | ||
| - You cannot change the type of columns for $HYPERTABLEs with $COLUMNSTORE enabled. See [Altering $HYPERTABLEs with $COLUMNSTORE enabled][alter-schema] for how to do it instead. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with 2.24 this is no longer tied to columnstore being enabled but to individual chunks using columnstore
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will keep in mind, thank you. |
||
| - For columns with statistics enabled, you can only change to integer or timestamp types. | ||
| To change to other types, first disable statistics using `disable_column_stats`. | ||
|
|
||
| ### Drop a column | ||
|
|
||
| You can drop a column from a $HYPERTABLE using the `ALTER TABLE` command. In this | ||
| example, the `humidity` column is dropped from the `conditions` $HYPERTABLE: | ||
|
|
||
| ```sql | ||
| ALTER TABLE conditions | ||
| DROP COLUMN humidity; | ||
| ``` | ||
|
|
||
| You cannot drop partitioning columns. | ||
|
|
||
| ## Drop a hypertable | ||
|
|
||
| Drop a hypertable using a standard $PG [`DROP TABLE`][postgres-droptable] | ||
| Drop a $HYPERTABLE using a standard $PG [`DROP TABLE`][postgres-droptable] | ||
| command: | ||
|
|
||
| ```sql | ||
| DROP TABLE weather; | ||
| ``` | ||
|
|
||
| All data chunks belonging to the hypertable are deleted. | ||
| All data $CHUNKs belonging to the $HYPERTABLE are deleted. | ||
|
|
||
| [postgres-droptable]: https://www.postgresql.org/docs/current/sql-droptable.html | ||
|
|
||
|
|
||
|
|
||
| [postgres-altertable]: https://www.postgresql.org/docs/current/sql-altertable.html | ||
| [hypertable-create-table]: /api/:currentVersion:/hypertable/create_table/ | ||
| [install]: /getting-started/:currentVersion:/ | ||
|
|
@@ -112,4 +141,5 @@ All data chunks belonging to the hypertable are deleted. | |
| [hypercore]: /use-timescale/:currentVersion:/hypercore/ | ||
| [secondary-indexes]: /use-timescale/:currentVersion:/hypercore/secondary-indexes/ | ||
| [timestamps-best-practice]: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_timestamp_.28without_time_zone.29 | ||
| [uuidv7_functions]: /api/:currentVersion:/uuid-functions/ | ||
| [uuidv7_functions]: /api/:currentVersion:/uuid-functions/ | ||
| [alter-schema]: /use-timescale/:currentVersion:/schema-management/alter/#altering-hypertables-with-columnstore-enabled | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in a sightly different wording and linked to the dedicated page about it