# Is it possible to partition a table after it's created and data inserted into it?

**URL:** <https://community.cratedb.com/t/is-it-possible-to-partition-a-table-after-its-created-and-data-inserted-into-it/1023>\
**Category:** CrateDB\
**Created:** [February 24, 2022, 10:26am UTC](https://community.cratedb.com/t/is-it-possible-to-partition-a-table-after-its-created-and-data-inserted-into-it/1023 "2022-02-24T10:26:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emre\_Sevinc](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/emre_sevinc/32/375_2.png) [@Emre\_Sevinc](https://community.cratedb.com/u/Emre_Sevinc)\
**Post date:** [February 24, 2022, 10:26am UTC](https://community.cratedb.com/t/is-it-possible-to-partition-a-table-after-its-created-and-data-inserted-into-it/1023/1 "2022-02-24T10:26:05Z")

</div>

Hello,

Is it possible to partition a table **after** it’s created and data inserted into it?

I read the following:

- [Sharding and Partitioning Guide for Time Series Data](https://community.cratedb.com/t/sharding-and-partitioning-guide-for-time-series-data/737)
- [Partitioned tables — CrateDB: Reference](https://crate.io/docs/crate/reference/en/4.7/general/ddl/partitioned-tables.html)
- [Altering tables — CrateDB: Reference](https://crate.io/docs/crate/reference/en/4.7/general/ddl/alter-table.html)
- [ALTER TABLE — CrateDB: Reference](https://crate.io/docs/crate/reference/en/4.7/sql/statements/alter-table.html)

The last document says “While columns can be added at any time, adding a new generated column is only possible if the table is **empty**.” So I guess it’s not possible.

I have some tables with time series data, millions of rows, that are not partitioned. This is why I’ve been trying to find out if this is possible.

If it’s not possible to partition an existing table with data already inserted, would the following be feasible in CrateDB?

- Create a similar table, but with an added generated column to be used as the partitioning column.
- INSERT INTO that similar table from the **un-partitioned** table.
- RENAME the **un-partitioned** to some other name.
- RENAME the **partitioned** table to the original **un-partitioned** name.
- DROP the **un-partitioned** table.

My concern with the plan above:

- Is renaming tables an atomic operation?
- How disruptive it is? If the tables in question have a few hundred million rows (on the order of 10s of GBs), would the renaming operation take more than a few seconds?

---

<div class="post-metadata">

**Author:** ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)\
**Post date:** [February 24, 2022, 10:34am UTC](https://community.cratedb.com/t/is-it-possible-to-partition-a-table-after-its-created-and-data-inserted-into-it/1023/2 "2022-02-24T10:34:30Z")

</div>

You could probably use `ALTER CLUSTER SWAP TABLE` (see [ALTER CLUSTER — CrateDB: Reference](https://crate.io/docs/crate/reference/en/4.7/sql/statements/alter-cluster.html#swap-table) ) which only takes a few ms/seconds

Changing from non-partitioned to partitioned is unfortunately not possible right now.
