Retool Database - Return UUID after Insert

Hi there. I am making an insert into the retool DB from a Workflow using the Bulk Insert Records action.
image

The UUID field on the db 'parts' table gets auto-generated when the data row is inserted. Does anyone know if I can get the UUID returned as part of the same call...? There is some data returned, but no UUIDs
image
Any thoughts gratefully received
Adam

what is key name of your uuid, as I know if your use retool hosted DB, there is not uuid will auto-generated. unless you genernate it with js, than pass it to insert data.

could you share screenshot of you database?

@turps808 you can use RETURNING at the at of your INSERT, eg:

INSERT INTO table (firstname, lastname) VALUES ('John, 'Doe') RETURNING uuid, firstname;

This will return the uuid and firstname after insertion. Or use only uuid or * for all fields

1 Like

That works perfectly - thanks @mbruijnpff

Taking it a step further, I am looking to do a bulk insert from an array of objects, and then return the id. Whilst testing, the below has been successful in terms of passing in multiple rows at the same time and getting the id's back.
image

I would like to pass in an array of objects from another query - do you have any thoughts on how that might be achieved? So as an example, in the screenshot below I am looking to take the build_id and file_name elements from each item in the query12.data array, insert them, and then return the id of each new row

image

Any thoughts would be much appreciated

Adam

JS is not my strongest, but I would re-map the values first using a JS Query or Transformer with something like this:

const data = query12.data;
return dataArray = data.map(({ build_id, filename }) => [build_id, filename]);

Then use the output of this to insert into you db

insert into test (build_id, file_name)
values {{jsquery.data}}
returning _id
1 Like