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

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