Skip to content
Advertisement

A relative path is not allowed to use COPY to a file

I made a function so that when I click on a button it made a “COPY TO” querie to the server. The goal is to export a table database in .csv that goes to the user downloads of my application. I first tried to write the database table in an existing file with the following querie :

async function exportDatabase(req, res){
return db.any("copy tag_7z8eq73 to 'C:UsersNew-rFid-ConceptDocumentsBioTech_mathistag_7z8eq73.csv' delimiters '|' CSV HEADER")
.then(rows => {
        res.json(rows)
    })
    .catch(error => {
        console.log(error)
    });   

}

But the following error is returning : “A relative path is not allowed to use COPY to a file”

From what I understand I have to write to STDOUT but when I send this request nothing happens in my VScode terminal or anything else.

I tried :

“COPY tag_7z8eq73 TO STDOUT csv header”

“COPY tag_7z8eq73 TO STDOUT”

“copy tag_7z8eq73 TO STDOUT”

and others..

Do you know what would be the query that would allow me to create a .csv file with my node.js application?

Thank you for your help!

Advertisement

Answer

Finally instead of doing with the complicated ‘COPY TO’ command line, I ‘SELECT’ the database, push it into an array, convert it to json and create a csv file using the ‘vue-json-to-csv’ plugin.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement