Readers,
A table was created to perform a sum function on a group of rows:
create table testgroupsum (itemname varchar(50),date date,amount numeric);
CREATE TABLE
set datestyle to DMY;
SET
insert into testgroupsum (itemname,date,amount) values ('item
1','2013-01-01','100');
INSERT 0 1
insert into testgroupsum (itemname,date,amount) values ('item
2','2013-01-10','35');
INSERT 0 1
insert into testgroupsum (itemname,date,amount) values ('item
3','2013-02-20','50');
INSERT 0 1
insert into testgroupsum (itemname,date,amount) values ('item
a','2013-01-25','-500');
INSERT 0 1
insert into testgroupsum (itemname,date,amount) values ('item
b','2013-02-28','-20');
INSERT 0 1
copy testgroupsum (SELECT EXTRACT(month FROM(date)), SUM(amount) FROM
testgroupsum GROUP
(> BY EXTRACT(month FROM(date))) to /home/r/tmp/data.csv;
ERROR: syntax error at or near "SELECT"
LINE 1: copy testgroupsum (SELECT EXTRACT(month FROM(date)), SUM(amo...
^
\copy testgroupsum (SELECT EXTRACT(month FROM(date)), SUM(amount) FROM
testgroupsum GROUP
BY EXTRACT(month FROM(date))) to /local/path/to/data.csv;
\copy: parse error at ")"
SELECT EXTRACT(month FROM(date)), SUM(amount) FROM testgroupsum GROUP
BY EXTRACT(month FROM(date));
date_part | sum
-----------+------
1 | -365
2 | 30
(2 rows)
What is the cause of the error, preventing export of the query as a csv file?