I have a table with two columns application and projects. While application is a simple column of varchar type, projects should hold array of jsonb objects.
A sample record is:
application | projects
-----------------------
App1 | [{"project": "project1", "url":"url1"},{"project": "project2", "url": "url2"}]
Now there is a json file which holds the data to be inserted into this table programmatically in the exact same structure as this table which needs to be read through Node.js and inserted into the table.
My question is how do I write an insert query which inserts the projects field correctly into the table. I am a beginner in Postgresql and unaware of the function that can do this. I want to write something like this:
Insert into <tablename> values('App1',
some_function_that_converts_string_to_jsonb_array('[{"project": "project1", "url":"url1"},
{"project": "project2", "url": "url2"}]');
What function of Postgresql can achieve this? I have tried using jsonb_build_array but it is not working.
Thanks!
EDIT:
The value of the projects column should be that I can query on it.
. . . values ('App1', '[1, 2, 3]')"[" must introduce explicitly-specified array dimensions.. The type of projects column isjsonb[]projectscolumn tojsonb. Please see: stackoverflow.com/a/62917486/13808319