Realm auto increment primary key with sync to postgres database

482 views Asked by At

Best practise to use primary key for data synced from postgres to ROS then to app.

User can insert data to these tables and they will be

synced back to postgres.

Definitely

maxId + 1 is not the solution

as multiple users can insert at same time. so if we can use a UUID should I store the it in postgres too or is it only for ROS?

And realm doesn't allow to skip primary key while inserting (which could be handled by postgres).

Or is there any other better practise to handle two way data sync for realm & postgres

1

There are 1 answers

2
mentallurg On

Use sequence. It will make sure each of parallel requests will have a new ID, without collisions with other users / requests / threads.

With Google you will find multiple examples. Just one: https://www.ntchosting.com/encyclopedia/databases/postgresql/sequence/