4

I'm trying to locally download the results of a query as csv on a postgres instance that I have read-only access to (v8.0.2). I've truly read 10 different ways of going about this and have tried implementing them all (here, here, here, here, and here), but every single time I try to execute the copy command, I get the following error:

ERROR:  syntax error at or near "STDOUT"

Here are five of the roughly 20 permutations I have tried. The foo_bar table is a temporary table that was created as the output of a query.

=> \copy "pg_temp_5.foo_bar" TO '/Users/baz/Downloads/foo_bar.csv' DELIMITER ',' CSV
ERROR:  syntax error at or near "STDOUT"
LINE 1: COPY  "pg_temp_5.foo_bar" TO STDOUT DELIMITER ',' CSV

=> \copy "pg_temp_5.foo_bar" TO '/Users/baz/Downloads/foo_bar.csv' CSV
ERROR:  syntax error at or near "STDOUT"
LINE 1: COPY  "pg_temp_5.foo_bar" TO STDOUT CSV

=> \copy "pg_temp_5.foo_bar" TO '/Users/baz/Downloads/foo_bar.csv' WITH FORMAT "csv"
ERROR:  syntax error at or near "STDOUT"
LINE 1: COPY  "pg_temp_5.foo_bar" TO STDOUT WITH FORMAT "csv"

=> \copy pg_temp_5.foo_bar TO '/Users/baz/Downloads/foo_bar.csv' With CSV
ERROR:  syntax error at or near "STDOUT"
LINE 1: COPY  pg_temp_5.foo_bar TO STDOUT With CSV

=> \copy foo_bar TO foo_bar.csv With CSV
ERROR:  syntax error at or near "STDOUT"
LINE 1: COPY  foo_bar TO STDOUT With CSV

I figure that it isn't a permissions issue, as if it were, I would be thrown a "permission denied" when I try to run the command. I also know that there have been similar issues with the \copy command as documented by postgres here, but nothing has been noted specifically with regards to my case. Any help would be greatly appreciated!

yungblud
  • 388
  • 4
  • 17
  • `\copy` syntax looks fine to me. What's the version of `psql`? 8.0.2 too? If yes I would try a newer version. – Michel Milezzi Jun 29 '17 at 19:28
  • Why you are using an un-supported and discontinued Postgres version? –  Jun 29 '17 at 19:58
  • @a_horse_with_no_name Unfortunately, and rather crappily, changing the version is something I have absolutely no immediate control over. – yungblud Jun 29 '17 at 20:27
  • 1
    @michel.milezzi psql version is also 8.0.2, and I sincerely wish I could upgrade, but it isn't something I have control over. I've gotta figure it out using what's at hand. – yungblud Jun 29 '17 at 20:29
  • @yungblud Well, even you cannot upgrade **server** version, you can still connect to it with a newer version of `psql`. – Michel Milezzi Jun 29 '17 at 20:35
  • 1
    @michel.milezzi My bad - I completely misread your question! The client version that I was using is very new, 9.6.3 – yungblud Jun 29 '17 at 20:41
  • I noticed Redshift declares itself as Postgres version 8. Any chance you're actually on Redshift, @yungblud? `PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.17498` – combinatorist Jul 30 '20 at 20:19

0 Answers0