我是一个postrgresql noob。我在远程服务器上使用psql。我已经提出了一个我想作为csv下载的查询。该查询可以自行运行。
查询中涉及两个表。第一个:
CREATE TABLE players (username varchar(100), skill varchar(100),id int);
INSERT INTO players VALUES
('user1', 'flight', 1),
('user2', 'run', 2),
('user3', 'run', 3),
('user4', 'flight', 4),
('user5', 'flight', 5),
('user6', 'climb', 6),
('user7', 'flight', 7),
('user8', 'flight', 8),
('user9', 'flight', 9),
('user10', 'climb', 10);
第二个表是临时的,我只需要它就可以提取这个csv:
CREATE TEMP TABLE specific_players (username varchar(100));
INSERT INTO specific_players VALUES
('user2'),
('user5'),
('user7'),
('user9');
我的查询如下:
select * from players p inner join specific_players sp USING (username);
就像我说的那样,效果很好。 但是当我尝试将其包装在复制命令中时
\copy (select * from players inner join specific_players USING (username)) to '/Users/me/path/to/folder/filename.csv' with csv
我收到错误:
ERROR: syntax error at or near "("
LINE 1: COPY ( select * from players p join specific_playe...
文件是在我的计算机上创建的,但它是空的。知道我做错了吗?