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

167
Visualizações
How to use postgres COPY in nestjs?

I'm building a nestjs application that uses postgres. I have some big data (from 100 to 10 millions entries and more) that I receive through an API. I need to write this data to a postgres DB.

I researched a bit and found out that I should use COPY to do a bulk insert.

I tested COPY in console mode using psql and it works. But I can't find any example how to do it through js code.

Here is what I've tried:

const queryRunner = this.connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();

//throws error 'syntax error at or near "123"'
const query = `COPY ${table}(key) FROM stdin \n123\t\n321\t\n147\t\n\\.\n`;

// using INSERT works as expected
//const query = `INSERT INTO ${table}(key) VALUES ('123'), ('321'), ('147');`;
await queryRunner.query(query);


await queryRunner.commitTransaction();
await queryRunner.release();

The above code throws this error:

ERROR: syntax error at or near "123" at character 33

Can anyone explain/point into direction how to solve this? Thanks

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