I need to add an array of string values into postgre but i get this error :
malformed literal array.
This array is taken from a form inside a hidden input value and has a regular array format: ['bla','bala']
This is the form (the array is "labelProduitsArray") with action = "post" :
$(`
<div id='LinePanier'>
<label for="LabelProduitInput" id='LabelProduit'>${labelProduit}</label>
<input type="hidden" name="LabelProduitInput" id="LabelProduitInput" value=${labelProduitsArray}>
<label for="PrixProduitInput" id='PrixProduit'>${prixProduit}</label>
<input type="hidden" name="PrixProduitInput" id="PrixProduitInput" value=${produitPrixArray}>
<br>
</div>
<label for="TotalProduit" id='TotalProduitLabel'>Total :</label>
<input type="hidden" name="TotalProduit" id="TotalProduitInput" value=${totalProduitString}>
<p id='TotalProduit'>${totalProduitString}</p>
`).insertBefore('#BoutonRecapPanier');
and this is my query (I'm using Deno oak framework):
const addProductPanier = async ({request, response}:{request:any,response:any}) =>{
const body = await request.body({type: 'form-data'});
const product = await body.value.read();
if(!request.hasBody){
response.status = 400;
response.body ={
success: false,
msg: 'No data'
}
} else{
try{
await client.connect();
const result = await client.queryObject("INSERT INTO panierencours (labelpanier,prixpanier,totalpanier) VALUES ($1,$2,$3);",
product.fields.LabelProduitInput,
product.fields.PrixProduitInput,
product.fields.TotalProduit,
);
response.status = 201;
response.redirect('/OBV/panier')
} catch(err){
response.status = 200;
response.body = {
success: false,
msg: err.toString()
}
} finally{
await client.end();
}
}
};
In pgAdmin I set "labelpanier" column type into text[].
Is this issue coming from the wrong array format or is it a wrong query syntax to store an array?