Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!