Faking the result of RANDOMSTRING() to pre-load data in tables using CSV files

I had the need to preload some tables during app development with data to support testing. In this case, I do not have a meaningful construct for the ID column which means the best practice is to use the RANDOMSTRING() function in the expression editor to ensure a unique ID.

Having used it in the past, the Linux utility pwgen came to mind. Not only can you specify what types of characters to use, the length, but also the number of “passwords” to generate.

Let’s say you need unique IDs for 10 records for data you already have in a CSV file, the command would look like this:

$ pwgen -1 17 10
kotai1aeKoor0Shoa
sah6ee5nioSh3quaa
Raed8Eroow8theicu
rahbo2kair0Yeisoo
eetheiv5ieP1phee4
deThae7eeNaewool7
jo8lieGh4Yiegheig
kohKae4goowaek8ai
ainiegoo4iL7aehai
eg7UzohYah9eeX8Ye

Where:

  • -1: (number one) prints all the passwords in one column. The default is 8 which is not very CSV friendly.
  • 17: is the number of characters to include in the password. 17 matches the output of RANDOMSTRING()
  • 10: The number of passwords to generate.

Now you only need to copy and paste the into the ID column of your CSV file.

9 Likes

Love it! Thanks for sharing Richard :grinning: