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

140
Views
¿Cómo insertar una matriz de datos por columna en MySQL?

Tengo matrices apiladas en 1 matriz y me gustaría insertar cada matriz por columna en MySQL. Llegué a insertar todos los datos en matrices en 1 columna, pero quiero insertar una matriz por columna. Por favor, vea la captura de pantalla y el código a continuación.

Imagen de la pila de matriz

 con.connect(async(err)=>{ const x = await getStock() if(err){ console.log(err); return err; }else{ console.log("DB ok"); } console.log("connected"); x.filter(item=>item===undefined?false:true).map(item=>item.forEach(item=>{ const sql ="INSERT INTO test (testCol1) VALUES ?"; const values=[ [item] ]; con.query(sql,[values],(err,result)=>{ if(err)throw err; console.log("this have been recorded"+result); }); })); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Acabo de encontrar una solución para este caso. Puede ser un poco confuso, pero está funcionando. Tal vez exista una solución más fácil y comprensible, pero esta es la solución que tengo en este momento.

En el código anterior, estaba usando solo 1 iterador de matriz, que me devolvía una matriz. Decidí iterar la matriz devuelta para obtener cada número entero e insertar datos en MySQL, también (test${i+1}) establece la matriz en la columna necesaria.

 x.filter(item=>item===undefined?false:true).forEach((item,i)=>{ item.forEach(item=>{ const sql =`INSERT INTO test (test${i+1}) VALUES ?`; const values=[ [item] ]; con.query(sql,[values],(err,result)=>{ if(err)throw err; console.log("this have been recorded"+result); }); }) });
about 4 years ago · Juan Pablo Isaza Report
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!