2 -- Test cases for COPY (select) TO
4 create table test1 (id serial, t text);
5 insert into test1 (t) values ('a');
6 insert into test1 (t) values ('b');
7 insert into test1 (t) values ('c');
8 insert into test1 (t) values ('d');
9 insert into test1 (t) values ('e');
10 create table test2 (id serial, t text);
11 insert into test2 (t) values ('A');
12 insert into test2 (t) values ('B');
13 insert into test2 (t) values ('C');
14 insert into test2 (t) values ('D');
15 insert into test2 (t) values ('E');
17 as select 'v_'||t from test1;
30 copy v_test1 to stdout;
31 ERROR: cannot copy from view "v_test1"
32 HINT: Try the COPY (SELECT ...) TO variant.
34 -- Test COPY (select) TO
36 copy (select t from test1 where id=1) to stdout;
39 -- Test COPY (select for update) TO
41 copy (select t from test1 where id=3 for update) to stdout;
46 copy (select t into temp test3 from test1 where id=3) to stdout;
47 ERROR: COPY (SELECT INTO) is not supported
51 copy (select * from test1) from stdin;
52 ERROR: syntax error at or near "from"
53 LINE 1: copy (select * from test1) from stdin;
58 copy (select * from test1) (t,id) to stdout;
59 ERROR: syntax error at or near "("
60 LINE 1: copy (select * from test1) (t,id) to stdout;
65 copy (select * from test1 join test2 using (id)) to stdout;
74 copy (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) to stdout;
84 copy (select * from (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) t1) to stdout;
92 -- Test headers, CSV and quotes
94 copy (select t from test1 where id = 1) to stdout csv header force quote t;
98 -- Test psql builtins, plain table
100 \copy test1 to stdout
109 \copy v_test1 to stdout
110 ERROR: cannot copy from view "v_test1"
111 HINT: Try the COPY (SELECT ...) TO variant.
113 -- Test \copy (select ...)
115 \copy (select "id",'id','id""'||t,(id + 1)*id,t,"test1"."t" from test1 where id=3) to stdout
123 -- psql handling of COPY in multi-command strings
124 copy (select 1) to stdout\; select 1/0; -- row, then error
126 ERROR: division by zero
127 select 1/0\; copy (select 1) to stdout; -- error only
128 ERROR: division by zero
129 copy (select 1) to stdout\; copy (select 2) to stdout\; select 0\; select 3; -- 1 2 3
137 create table test3 (c int);
138 select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 1