# What is the recommended way to insert a new column & data into a table with 20k+ records

**URL:** <https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080>\
**Category:** Baserow Help\
**Tags:** baserow, help-wanted\
**Created:** [July 10, 2023, 12:54pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080 "2023-07-10T12:54:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xJJW](https://community.baserow.io/user_avatar/community.baserow.io/0xjjw/32/1085_2.png) [@0xJJW](https://community.baserow.io/u/0xJJW)\
**Post date:** [July 10, 2023, 12:54pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080/1 "2023-07-10T12:54:13Z")

</div>

I have a customer who needs to add a new column to a relatively large table with over 20,000 rows.

The table has numerous linked records, so it’s more complex than exporting and reimporting the table, as the references will be lost.

Is there any workaround or recommendation for solving this issue?

Environment: Hosted  
New column data type: String

Many thanks,  
Joel

---

<div class="post-metadata">

**Author:** ![nigel](https://community.baserow.io/user_avatar/community.baserow.io/nigel/32/51_2.png) [@nigel](https://community.baserow.io/u/nigel)\
**Post date:** [July 10, 2023, 1:02pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080/2 "2023-07-10T13:02:22Z")

</div>

Is the goal to add a new column, but with some predefined data for that new column and not just a blank new one?

---

<div class="post-metadata">

**Author:** ![0xJJW](https://community.baserow.io/user_avatar/community.baserow.io/0xjjw/32/1085_2.png) [@0xJJW](https://community.baserow.io/u/0xJJW)\
**Post date:** [July 10, 2023, 1:13pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080/3 "2023-07-10T13:13:22Z")

</div>

Yes, all of the records will have a unique value.

If there weren’t so many records, I would write a script to update the records via the API, but I assume this would go against the TOS as I am on the shared hosting plan.

Additionally, I would like to make the column the Primary column on the table and set the current primary column as a ‘normal’ column.

Thank you for the swift response.

---

<div class="post-metadata">

**Author:** ![nigel](https://community.baserow.io/user_avatar/community.baserow.io/nigel/32/51_2.png) [@nigel](https://community.baserow.io/u/nigel)\
**Post date:** [July 10, 2023, 1:20pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080/4 "2023-07-10T13:20:59Z")

</div>

Right now the easiest way to do this would be using our [`batch update` API endpoint](https://api.baserow.io/api/redoc/#tag/Database-table-rows/operation/batch_update_database_table_rows) and a script. It’s not against the TOS to use our API in a sensible way, i’d suggest adding a couple seconds sleep between batch update calls to be safe and go for it.

Otherwise your only manual option is to make a blank new column and then to copy and paste in the values 200 rows at a time, which is not ideal.

We have a prioritized issue to add the ability for the importer to also do an UPSERT based on some key column, partially tracked here: [Introduce endpoint to upsert a row in a table (#1395) · Issues · Baserow / baserow · GitLab](https://gitlab.com/baserow/baserow/-/issues/1395) so hopefully this will become much easier in the near future. We are also alternatively going to add support for pasting in more than 200 values at once.

Separately on making this new field the primary key, it isn’t yet possible to swap which field is the primary field, you can see the issue tracking this here: [Allow changing the primary field (#1301) · Issues · Baserow / baserow · GitLab](https://gitlab.com/baserow/baserow/-/issues/1301).

One way i’d suggest to get around this is to:

1. Duplicate/snapshot the table to make a backup (please note the ID’s of the table/fields/views will all be different in the new duplicate/restored snapshot).
2. Make a new formula column
3. use the `field('my primary field')` name to make the formula column copy all the primary field data into this new column
4. convert the formula column to text to persist the copied data.
5. Now you can batch update the primary field with your script.

---

<div class="post-metadata">

**Author:** ![0xJJW](https://community.baserow.io/user_avatar/community.baserow.io/0xjjw/32/1085_2.png) [@0xJJW](https://community.baserow.io/u/0xJJW)\
**Post date:** [July 10, 2023, 1:35pm UTC](https://community.baserow.io/t/what-is-the-recommended-way-to-insert-a-new-column-data-into-a-table-with-20k-records/3080/5 "2023-07-10T13:35:42Z")

</div>

Thank you Nigel, I will try this 😃
