2 -- Test cases for COPY (select) TO
4 create table test1 (id serial, t text);
5 NOTICE: CREATE TABLE will create implicit sequence "test1_id_seq" for serial column "test1.id"
6 insert into test1 (t) values ('a');
7 insert into test1 (t) values ('b');
8 insert into test1 (t) values ('c');
9 insert into test1 (t) values ('d');
10 insert into test1 (t) values ('e');
11 create table test2 (id serial, t text);
12 NOTICE: CREATE TABLE will create implicit sequence "test2_id_seq" for serial column "test2.id"
13 insert into test2 (t) values ('A');
14 insert into test2 (t) values ('B');
15 insert into test2 (t) values ('C');
16 insert into test2 (t) values ('D');
17 insert into test2 (t) values ('E');
19 as select 'v_'||t from test1;
32 copy v_test1 to stdout;
33 ERROR: cannot copy from view "v_test1"
34 HINT: Try the COPY (SELECT ...) TO variant.
36 -- Test COPY (select) TO
38 copy (select t from test1 where id=1) to stdout;
41 -- Test COPY (select for update) TO
43 copy (select t from test1 where id=3 for update) to stdout;
48 copy (select t into temp test3 from test1 where id=3) to stdout;
49 ERROR: COPY (SELECT INTO) is not supported
53 copy (select * from test1) from stdin;
54 ERROR: syntax error at or near "from"
55 LINE 1: copy (select * from test1) from stdin;
60 copy (select * from test1) (t,id) to stdout;
61 ERROR: syntax error at or near "("
62 LINE 1: copy (select * from test1) (t,id) to stdout;
67 copy (select * from test1 join test2 using (id)) to stdout;
76 copy (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) to stdout;
86 copy (select * from (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) t1) to stdout;
94 -- Test headers, CSV and quotes
96 copy (select t from test1 where id = 1) to stdout csv header force quote t;
100 -- Test psql builtins, plain table
102 \copy test1 to stdout
111 \copy v_test1 to stdout
112 ERROR: cannot copy from view "v_test1"
113 HINT: Try the COPY (SELECT ...) TO variant.
114 \copy: ERROR: cannot copy from view "v_test1"
115 HINT: Try the COPY (SELECT ...) TO variant.
117 -- Test \copy (select ...)
119 \copy (select "id",'id','id""'||t,(id + 1)*id,t,"test1"."t" from test1 where id=3) to stdout