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

84
Vistas
SQL insert array of string - issues with .join(', ')

Currently I create a string with JavaScript that is used as a SQL query. It reads a number of rows from an Excel sheet and then creates the SQL query by combining all those datapoints with .join(','). I want to add added a column that is a list of tags.

It’s a comma separated array. When my string gets .joined(',')ed it just becomes a string.

Technically its still an array because its being added to my SQL query string as ARRAY['list, of, things'] but I need it to be in my SQL query string as ARRAY['list', 'of', 'things']. Any way to prevent this?

Snip it of code. company[3] is passed in as an array of strings:

const tagsPresent = company[3] !== null;

return format(
        `(%L, %L, ${
          tagsPresent ? `'{${company[3]}}'` : 'NULL::text[]'
          // I've also tried 'ARRAY[${company[3]}]' and ARRAY['+ company[3] +']

        })`,
        company[1],
        company[2]
      );
    })
    .join(', ');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I was able to solve this by using a map.

${
          tagsPresent
            ? `ARRAY[${company[3]
                .split(',')
                .map((tag) => "'" + tag + "'")
                .toString()}]`
            : 'NULL::text[]'
        })
about 4 years ago · Juan Pablo Isaza Denunciar
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