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:
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):
and
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 ''
These others "more classic" queries works perfectly.
Do you know what query I can write in my function to meet my need ?