Create if not exists

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

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.

1 Like

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

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.

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.

1 Like

I started a discussion on this use case here: Discussion: how do you sync an external database with baserow?

1 Like