Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!