I'm getting some issues while trying to export a query to CSV using the COPY function.
The COPY runs ok and exports the query successfully if not using custom filenames on the TO
.
The issue is related to add a "datestamp" (kinda) to the filename created.
declare var1 varchar(25);
DECLARE STATEMENT TEXT;
select into var1 current_date -1;
STATEMENT := 'COPY (SELECT * from myTable) To ''E'C:\\Exports\\export_'||var1||'.csv' ''With CSV';
EXECUTE STATEMENT;
In this case, var1
gets a value like 2013-12-16
and I need to add that to the filename to obtain export_2012-12-16.csv
I'm assuming that the '
are misplaced. I've tried several combinations without success and off course the error is ERROR: syntax error at or near "C"
.