# Create if not exists

**URL:** https://community.baserow.io/t/create-if-not-exists/2913
**Category:** Feature Ideas
**Tags:** baserow, api
**Created:** [June 14, 2023, 8:20pm UTC](https://community.baserow.io/t/create-if-not-exists/2913 "2023-06-14T20:20:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Chao](https://community.baserow.io/user_avatar/community.baserow.io/chao/32/1398_2.png) [@Chao](https://community.baserow.io/u/Chao)
#### Post date: [June 14, 2023, 8:20pm UTC](https://community.baserow.io/t/create-if-not-exists/2913/1 "2023-06-14T20:20:12Z")

</div>

I’m trying to sync a database with baserow, and what happens is it tries to write to baserow only if the primary key doesn’t exist.

So in SQL, I would do something like

```sql
INSERT INTO transactions
             (key, value)
             VALUES (a, b)
             ON CONFLICT (key)
             DO NOTHING

```

This does not exists for baserow.

What I do now is first ask baserow to return the list of `keys`, and then find the ones doesn’t exist, and create the rows.

---

<div class="post-metadata">

### Author: ![olgatrykush](https://community.baserow.io/user_avatar/community.baserow.io/olgatrykush/32/219_2.png) [@olgatrykush](https://community.baserow.io/u/olgatrykush)
#### Post date: [June 15, 2023, 10:26am UTC](https://community.baserow.io/t/create-if-not-exists/2913/2 "2023-06-15T10:26:03Z")

</div>

Thanks for sharing your idea @Chao, I’ll make sure to discuss it with the team 🙌

---

<div class="post-metadata">

### Author: ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)
#### Post date: [June 19, 2023, 2:56am UTC](https://community.baserow.io/t/create-if-not-exists/2913/3 "2023-06-19T02:56:01Z")

</div>

How are you attempting this, through the rest API? I had similar problems, and syncing one database with baserow will be a common pattern for many people I think. This is because baserow can serve as a front-end for apps which otherwise don’t have a GUI.

I don’t have a good solution, and airtable has the same issue. You need to retrieve all the records first, and separate your data into inserts and updates.

In my opinion, it would make sense to have a generic python module which can accept pandas dataframes.

---

<div class="post-metadata">

### Author: ![Chao](https://community.baserow.io/user_avatar/community.baserow.io/chao/32/1398_2.png) [@Chao](https://community.baserow.io/u/Chao)
#### Post date: [June 19, 2023, 6:09am UTC](https://community.baserow.io/t/create-if-not-exists/2913/4 "2023-06-19T06:09:07Z")

</div>

Yes, we just use the rest API.

Fortunately, our data are somewhat static. If ID is the same, we know all other field has to be the same. So we can batch by other fields, so each call we don’t have to look through everything.

---

<div class="post-metadata">

### Author: ![lucw](https://community.baserow.io/user_avatar/community.baserow.io/lucw/32/609_2.png) [@lucw](https://community.baserow.io/u/lucw)
#### Post date: [September 1, 2023, 2:33am UTC](https://community.baserow.io/t/create-if-not-exists/2913/5 "2023-09-01T02:33:27Z")

</div>

I started a discussion on this use case here: [Discussion: how do you sync an external database with baserow?](https://community.baserow.io/t/discussion-how-do-you-sync-an-external-database-with-baserow/3341)
