Generate a random string

Hey All-

With the release of r261 (started rollout last night) we add support for running connector functions as an automations action. This addition reminded me of one of the greatest connectors hacks of all time. I was wondering if I could use this to around the lack of expression editor in automations.

The initial case I ran into where I wanted expressions was to generate random strings for table records -

Most (maybe all) Tulip instances have a “Connectors Demo” SQL connector that can be used, this already has authentication details, making it a good sandbox to run SQL queries.

  1. Create a connector function
  2. Add the query select md5(NOW()::text) as random_string to this function
  3. Add a random_string output

md5 hashes the current time into a string, this time includes seconds down to 10.000ths , meaning unique values is nearly guaranteed.
[ninja edit: select CAST(FLOOR(RANDOM()*100000000000000) as text) as random_string; is another query that will guarantee a unique string]

From your automation:
4. Add an action to your automation, calling this function, and store its output to a variable


5. Use this variable wherever you need it! including as the id field on the table record creation action

Obviously, multiple random strings can be created as needed, for separate tables.


There are a bunch of other ways I could thinking about using this functionality:

Concatenating strings:


Multiplication, which could then be used downstream in your automation:


…and probably much much more.

Hope this unblocks someone!
Pete

5 Likes

Pete, you’re a wizard :smiley:

Done-it-again GIFs - Get the best GIF on GIPHY

1 Like

Yes! @Pete_Hartnett thank you for connecting the dots here before the feature even released!