2

This is for an approach that WRITES to a local file.

I am using SQL WorkBench and I'm connected to an AWS Redshift instance (which uses postgresql). I would like to run the query and have data exported from AWS Redshift to a local csv or text file. I have tried:

SELECT  transaction_date ,
    Variable 1 ,
    Variable 2 ,
    Variable 3 ,
    Variable 4 ,
    Variable 5 
From xyz
into OUTFILE 'C:/filename.csv'

But I get the following error:

ERROR: syntax error at or near "'C:/filename.csv'"
  Position: 148

into OUTFILE 'C:/filename.csv'
ZJAY
  • 2,517
  • 9
  • 32
  • 51
  • why not use PostgreSQL Web GUI eg SIDU to export to a csv – SIDU Jan 28 '16 at 00:45
  • Is there not a way to export to csv directly in the query? – ZJAY Jan 28 '16 at 00:47
  • 5
    what about this: http://stackoverflow.com/questions/1517635/save-pl-pgsql-output-from-postgresql-to-a-csv-file – SIDU Jan 28 '16 at 00:49
  • That is for an approach that runs entirely on the remote server. – ZJAY Jan 28 '16 at 01:29
  • 1
    @ZJAY - the link provided by @SIDU also covers exporting to local client using `psql` command-line, have you looked at that.. ? – vmachan Jan 28 '16 at 02:16
  • I get this error when trying that: An error occurred when executing the SQL command: \copy ( ERROR: syntax error at or near "\" Position: 1 \copy ( ^ – ZJAY Jan 28 '16 at 02:34
  • Are you writing your query correctly here? There is no `FROM` clause. If those are scalars, where are the functions they derive from? – Parfait Jan 28 '16 at 02:51
  • Yes, I truncated the query to get to the meat of the problem: into Outfile. – ZJAY Jan 28 '16 at 02:52
  • Remove the \ (backslash) in front of [COPY](http://www.postgresql.org/docs/8.3/static/sql-copy.html) which is a command line psql directive not SQL command. – Parfait Jan 28 '16 at 04:31
  • I did this - got this error: ERROR: syntax error at or near "(" Position: 5 – ZJAY Jan 28 '16 at 13:34
  • copy( SELECT variable 1 , variable 2 , variable 3 , – ZJAY Jan 28 '16 at 13:34

0 Answers0