Ludvig
05/09/2022, 12:13 PMsql
CREATE FUNCTION test_function(products_object_array_input some_data_type) -- what should the data type be? array? jsonb[]?
An array of objects that I would pass into the function could look like this:
json
[
{ "productID": 3, "quantity": 5 },
{ "productID": 1, "quantity": 2 }
]
First question: What should I set the products_object_array_input data type as? array? jsonb[]?
Second question: I then want to loop over the array to insert the values of the object array. Again, using plpgsql. How?
sql
-- I want to loop over cart_array_input and do this for every object in the array. Sorry for pseudo-code. i = iterator
insert into order_item(product_id, quantity)
values(products_object_array_input[i].productID, products_object_array_input[i].quantity);
Needle
05/09/2022, 12:13 PMLudvig
05/09/2022, 12:15 PMNeedle
05/09/2022, 12:50 PM