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

197
Views
How to write a COPY TO query with node js

I would like to be able to export a PostgreSQL table as a csv file with node.js and have it appear in the user's downloads - like this:

enter image description here

When I press a button ('export to csv') function is called so that a SQL request is sent to the server.

However I'm not sure which query to use to meet my need.

I first tested these queries with the command line editor SQL (shell):

enter image description here

and

enter image description here

Here are some of the queries I have tried

async function exportDatabase(req, res){
return db.any('COPY tag_7z8eq73 TO STDOUT')
.then(rows => {
        res.json(rows)
    })
    .catch(error => {
        console.log(error)
    });   
}

or this query, but I can't use quotes like this ''

enter image description here

These others "more classic" queries works perfectly.

enter image description here

Do you know what query I can write in my function to meet my need ?

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!