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

165
Vistas
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 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