- My goal:
Build an order management app in Retool with a PostgreSQL (Supabase) backend. Insert one order into pedidos and multiple products (up to 20-25) into detalles_pedido using {{ carrito.value }} (array of objects with id, nombre, cantidad, descuento, subtotal). - Issue:
Query fails with invalid input syntax for type json or bigint: "{}". Script to prepare arrays (ids, cantidades, etc.) from carrito.value returns empty arrays. Suspect carrito.value is not a valid JSON array. - Steps I've taken to troubleshoot:
- Checked {{ carrito.value }} with SELECT {{ carrito.value }} AS carrito;, got "{"{"nombre":"Caldo albaca y ajo",...}"}".
- Tried SELECT {{ formatDataAsArray(carrito.value) }} AS carrito;, returned empty object string.
- Used previous script:
const productos = Array.isArray(carrito.value) ? carrito.value : ;
const productoid = item.id;
const descuento = (Number(numberInput1.value) || 0) / 100;
const precioUnitario = Number(item.precio) || 0;
const cantidad = parseInt(cantidadinput.value, 10) || 0;
const subtotalConDescuento = cantidad * precioUnitario * (1 - descuento);
const nuevoProducto = {
id: productoid,
nombre: productonombre.value,
cantidad: cantidad,
precioUnitario: precioUnitario,
descuento: 0,
subtotal: subtotalConDescuento
};
carrito.setValue([...productos, nuevoProducto]);
- Additional info:
Environment: Retool Cloud.
Screenshots:
Tables: pedidos (id SERIAL, cliente_id INT, vendedor INT), detalles_pedido (id SERIAL, pedido_id INT, producto_id INT, cantidad INT, subtotal NUMERIC, descuento NUMERIC).
Notes: New to Retool/JavaScript.
Help me fix carrito.value population and adjust the query for multiple products. Suggestions welcome!


