]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/copyselect.out
Have \copy go through SendQuery
[postgresql] / src / test / regress / expected / copyselect.out
1 --
2 -- Test cases for COPY (select) TO
3 --
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');
18 create view v_test1
19 as select 'v_'||t from test1;
20 --
21 -- Test COPY table TO
22 --
23 copy test1 to stdout;
24 1       a
25 2       b
26 3       c
27 4       d
28 5       e
29 --
30 -- This should fail
31 --
32 copy v_test1 to stdout;
33 ERROR:  cannot copy from view "v_test1"
34 HINT:  Try the COPY (SELECT ...) TO variant.
35 --
36 -- Test COPY (select) TO
37 --
38 copy (select t from test1 where id=1) to stdout;
39 a
40 --
41 -- Test COPY (select for update) TO
42 --
43 copy (select t from test1 where id=3 for update) to stdout;
44 c
45 --
46 -- This should fail
47 --
48 copy (select t into temp test3 from test1 where id=3) to stdout;
49 ERROR:  COPY (SELECT INTO) is not supported
50 --
51 -- This should fail
52 --
53 copy (select * from test1) from stdin;
54 ERROR:  syntax error at or near "from"
55 LINE 1: copy (select * from test1) from stdin;
56                                    ^
57 --
58 -- This should fail
59 --
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;
63                                    ^
64 --
65 -- Test JOIN
66 --
67 copy (select * from test1 join test2 using (id)) to stdout;
68 1       a       A
69 2       b       B
70 3       c       C
71 4       d       D
72 5       e       E
73 --
74 -- Test UNION SELECT
75 --
76 copy (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) to stdout;
77 a
78 v_a
79 v_b
80 v_c
81 v_d
82 v_e
83 --
84 -- Test subselect
85 --
86 copy (select * from (select t from test1 where id = 1 UNION select * from v_test1 ORDER BY 1) t1) to stdout;
87 a
88 v_a
89 v_b
90 v_c
91 v_d
92 v_e
93 --
94 -- Test headers, CSV and quotes
95 --
96 copy (select t from test1 where id = 1) to stdout csv header force quote t;
97 t
98 "a"
99 --
100 -- Test psql builtins, plain table
101 --
102 \copy test1 to stdout
103 1       a
104 2       b
105 3       c
106 4       d
107 5       e
108 --
109 -- This should fail
110 --
111 \copy v_test1 to stdout
112 ERROR:  cannot copy from view "v_test1"
113 HINT:  Try the COPY (SELECT ...) TO variant.
114 --
115 -- Test \copy (select ...)
116 --
117 \copy (select "id",'id','id""'||t,(id + 1)*id,t,"test1"."t" from test1 where id=3) to stdout
118 3       id      id""c   12      c       c
119 --
120 -- Drop everything
121 --
122 drop table test2;
123 drop view v_test1;
124 drop table test1;
125 -- psql handling of COPY in multi-command strings
126 copy (select 1) to stdout\; select 1/0; -- row, then error
127 1
128 ERROR:  division by zero
129 select 1/0\; copy (select 1) to stdout; -- error only
130 ERROR:  division by zero
131 copy (select 1) to stdout\; copy (select 2) to stdout\; select 0\; select 3; -- 1 2 3
132 1
133 2
134  ?column? 
135 ----------
136         3
137 (1 row)
138
139 create table test3 (c int);
140 select 0\; copy test3 from stdin\; copy test3 from stdin\; select 1; -- 1
141  ?column? 
142 ----------
143         1
144 (1 row)
145
146 select * from test3;
147  c 
148 ---
149  1
150  2
151 (2 rows)
152
153 drop table test3;