title: PostgreSQL export result as CSV from remote server
body: <p>I have read all other solutions and none adapts to my needs, I do not use Java, I do not have super user rights and I do not have API's installed in my server. </p>
  
  <p>I have select rights on a remote PostgreSQL server and I want to run a query in it remotely and export its results into a .csv file in my local server.</p>
  
  <p>Once I manage to establish the connection to the server I first have to define the DB, then the schema and then the table, fact that makes the following lines of code not work:</p>
  
  <pre><code>\copy schema.products TO '/home/localfolder/products.csv' CSV DELIMITER ','
  
  copy (Select * From schema.products) To '/home/localfolder/products.csv' With CSV;
  </code></pre>
  
  <p>I have also tried the following bash command:</p>
  
  <pre><code> psql -d DB -c "select * from schema.products;" &gt; /home/localfolder/products.csv
  </code></pre>
  
  <p>and logging it with the following result:</p>
  
  <blockquote>
    <p>-bash: home/localfolder/products.csv: No such file or directory</p>
  </blockquote>
  
  <p>I would really appreciate if someone can show a light on this.</p>