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');
11 create table test2 (id serial, t text);
12 insert into test2 (t) values ('A');
13 insert into test2 (t) values ('B');
14 insert into test2 (t) values ('C');
15 insert into test2 (t) values ('D');
16 insert into test2 (t) values ('E');
19 as select 'v_'||t from test1;
28 copy v_test1 to stdout;
30 -- Test COPY (select) TO
32 copy (select t from test1 where id=1) to stdout;
34 -- Test COPY (select for update) TO
36 copy (select t from test1 where id=3 for update) to stdout;
40 copy (select t into temp test3 from test1 where id=3) to stdout;
44 copy (select * from test1) from stdin;
48 copy (select * from test1) (t,id) to stdout;
52 copy (select * from test1 join test2 using (id)) to stdout;
56 copy (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) to stdout;
60 copy (select * from (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) t1) to stdout;
62 -- Test headers, CSV and quotes
64 copy (select t from test1 where id = 1) to stdout csv header force quote t;
66 -- Test psql builtins, plain table
72 \copy v_test1 to stdout
74 -- Test \copy (select ...)
76 \copy (select "id",'id','id""'||t,(id + 1)*id,t,"test1"."t" from test1 where id=3) to stdout
84 -- psql handling of COPY in multi-command strings
85 copy (select 1) to stdout\; select 1/0; -- row, then error
86 select 1/0\; copy (select 1) to stdout; -- error only
87 copy (select 1) to stdout\; copy (select 2) to stdout\; select 0\; select 3; -- 1 2 3
89 create table test3 (c int);
90 select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 1