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

267
Views
Error: literal de matriz con formato incorrecto, tratando de pasar una matriz a la columna TEXTO []

Así que tengo una matriz que se ha creado en Node.JS al insertar elementos en una matriz, que luego estoy tratando de configurar en una columna Text[] de PostgreSQL. Así que es algo como esto:

 var hours = [] for (x of hourStrings) { hours.push(x) // Here, x is something like {"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"} }

Mi elemento que estoy tratando de poner en una columna de Postgres se ve así:

 {{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"}}

y el error que me sale es este:

 error: malformed array literal: "{{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"},{"2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"}}"

Estoy consultando con esto:

 const client = await pool.connect() await client.query(`INSERT INTO tableName (hoursColumn) VALUES($1) ON CONFLICT DO NOTHING`, [hours]);

No veo dónde está el error en el objeto. No estoy seguro de cómo solucionar esto, cualquier ayuda es muy apreciada.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Para esto, en lugar de un bucle for, usé foreach y ¡pareció funcionar para mí! También cambié hourStrings.

 let hourStrings = ["2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00","2022-05-07T12:00:00+01:00 - 2022-05-07T16:00:00+01:00"] let hours = [] hourStrings.forEach(element => { hours.push(element) }); console.log(hours)
about 4 years ago · Juan Pablo Isaza Report

0

El problema está en el elemento vacío {} que tienes en el texto.

Además, cada elemento de la matriz debe tener la misma dimensión.

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!