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

204
Visualizações
postgres variable injection vs js template string

I am trying to make query returning fields a bit more flexible by passing in the column to be returned but if I use variable injection it will not work and if I use template string it'll work fine.

I am trying not to use template string as possible for these injections

  const select = ["_id", "status"]
  const selectFields = select.map(field => `"${field}"`).join(',');

  // using variable injection, the querying will try to query `'"_id","status"'`
  // which doesn't work
  const theRow = await db.oneOrNone(
    `SELECT $1
     FROM "TableName"`,
    [selectFields]
  );


  // if I use template string, it'll work properly
  const theRow = await db.oneOrNone(
    `SELECT ${selectFields}}
     FROM "TableName"`
  );

How can I make the query to query properly even with variable injection? Thanks in advance for any help / suggestions

about 4 years ago · Juan Pablo Isaza
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