I tried doing a "COPY (query) TO '/var/tmp/filename.csv' WITH CSV", which gave me an error. So I tried it w/o the WITH CSV... same error. I tried the query by itself which worked. As soon as I add the parenthesis and the COPY TO stuff I get the following error:
ERROR: syntax error at or near "("
SQL state: 42601
Character: 6
Here's a simple test I devised to make sure it wasn't my actual tables.
Expand|Select|Wrap|Line Numbers
- CREATE TABLE copytest (t1 char, t2 integer, t3 text) WITH OIDS;
- INSERT INTO copytest VALUES('a', 5, 'testing');
- INSERT INTO copytest VALUES('b', 4, 'this');
- INSERT INTO copytest VALUES('c', 3, 'should');
- INSERT INTO copytest VALUES('d', 2, 'work');
- INSERT INTO copytest VALUES('e', 1, 'right?');
- SELECT * FROM copytest;
Expand|Select|Wrap|Line Numbers
- -- This doesn't work
- COPY (SELECT * FROM copytest) TO '/var/tmp/copytest.csv' WITH CSV;
- -- This doesn't work either
- COPY (SELECT * FROM copytest) TO '/var/tmp/copytest.csv';
- -- Atleast this works, but isn't quite what I'm going for
- COPY copytest TO '/var/tmp/copytest.csv' WITH CSV;
Regards,
James