Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
How can i store an array from js as a column value in postgreSQL?

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?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda