I am currently building a custom JSON Schema form for my app to insert data into my database and it involves dynamic field generation. See schema below:
I want to push to a table in a pgsql db that has the columns release_name and track_name. However, I need to iterate the release_name over the number of track_names. At present I can only push the data in as release_name (as string) and track_name (as array if more than one track). Because the Track Name question in the form is dynamic and could have as many as 10 tracks created and then submitted I need the insert into statement to know to duplicate the same number of times as the number of tracks and have each track name inserted as a unique row.
I have seen this is somewhat possible using JS but I am not that skilled with the language unfortunately. Any help would be greatly appreciated!
Thank you for helping out - the correct PostgreSQL query is mostly the initial struggle here.
Realistically I was looking to do a simple INSERT INTO statement using the values generated from the form. However, I'm not quite sure how to write a SQL statement that can account for the undefinable range of answers that the form could generate.
It could be -
INSERT INTO table (release_title, track_name)
VALUES ({{ releaseJSONForm.data.releaseTitle }}, {{releaseJSONForm.data.trackList}})
But of course this results in the track_name column containing an array of elements. These elements need to be split up into unique rows where release_title is duplicated.
If that makes sense? I'm hoping to do it all in the retool/sql query but of course I understand if that's not possible. I know I could probably run a script in Python that does it outside Retool for me but hoping to keep it all in one place.