The following post is about our new Cloud beta feature, Retool Database. If you're not yet familiar with Retool Database, it combines a PostgreSQL database that's hosted by Retool with a spreadsheet-like interface to manage hosted data. You can read more about this feature on our docs.
We were chatting in community office hours about setting up a Retool database to generate primary keys with random integers, and I wanted to share what we came up with.
First, create your Retool Database table:
Next, go to the primary key (id) settings. Set the default value to SQL expression & type in your code. I am using
floor(random() * 1000 + 1) as an example (syntax described further here). You can use another Postgres expression that best fits your use case, just keep in mind you don't need the
Next, add any other columns you may want & test:
This is not a comprehensive tutorial of all the primary key settings (you can certainly have consecutive primary keys). I highly encourage you to research the best primary key strategy for your use case and come up with your own SQL expression if needed, but I hope this helps demonstrate the power of Retool Database!
Since this is a beta feature, it's still in active development & isn't available on-premise yet. Keep your eyes peeled for updates!