Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

93
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda