]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/copyselect.out
Do not allow Unique nodes to be scanned backwards. The code claimed that it
[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) 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) 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 \copy: ERROR:  cannot copy from view "v_test1"
115 HINT:  Try the COPY (SELECT ...) TO variant.
116 -- 
117 -- Test \copy (select ...)
118 --
119 \copy (select "id",'id','id""'||t,(id + 1)*id,t,"test1"."t" from test1 where id=3) to stdout
120 3       id      id""c   12      c       c
121 --
122 -- Drop everything
123 --
124 drop table test2;
125 drop view v_test1;
126 drop table test1;