I have a fully functioning compound PostgreSQL query...
SELECT * FROM
(SELECT date_trunc('day', date) date, (array_agg(open ORDER BY time
ASC))[1] o, MAX(high) h, MIN(low) l, (array_agg(close ORDER BY time
DESC))[1] c
FROM
(SELECT * FROM ES_test WHERE time BETWEEN
(SELECT pit_open FROM "contracts" WHERE root_symbol = '@ES' LIMIT 1)
AND
(SELECT pit_close FROM "contracts" WHERE root_symbol = '@ES' LIMIT 1))
AS pit
GROUP BY date_trunc('day', date) ORDER BY date) AS pit_daily INNER
JOIN trading_dates ON pit_daily.date = trading_dates.date;
I want to export the output of this query to a csv. I have tried the COPY method...
Copy (Select * From foo) To '/tmp/test.csv' With CSV DELIMITER ',';
and the \copy method...
\copy (SELECT * FROM persons) to 'C:\tmp\persons_client.csv' with
csv
without any success. When I try these I get multiple errors including parse errors or gets tangled up after one of the "AS" within the query or right after the "TO" that quotes the location to create the csv file. I get similar errors when I try to create a temp table or temp view. Any suggestions? This is the version...
'psql (PostgreSQL) 12.2 (Ubuntu 12.2-2.pgdg18.04+1)'