7 WHERE onek.unique1 < 2;
12 WHERE onek2.unique1 < 2;
15 -- SELECT INTO and INSERT permission, if owner is not allowed to insert.
17 CREATE SCHEMA selinto_schema;
18 CREATE USER regress_selinto_user;
19 ALTER DEFAULT PRIVILEGES FOR ROLE regress_selinto_user
20 REVOKE INSERT ON TABLES FROM regress_selinto_user;
21 GRANT ALL ON SCHEMA selinto_schema TO public;
22 SET SESSION AUTHORIZATION regress_selinto_user;
24 CREATE TABLE selinto_schema.tbl_withdata1 (a)
25 AS SELECT generate_series(1,3) WITH DATA;
26 INSERT INTO selinto_schema.tbl_withdata1 VALUES (4);
27 ERROR: permission denied for table tbl_withdata1
28 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
29 CREATE TABLE selinto_schema.tbl_withdata2 (a) AS
30 SELECT generate_series(1,3) WITH DATA;
32 --------------------------------------
33 ProjectSet (actual rows=3 loops=1)
34 -> Result (actual rows=1 loops=1)
37 -- WITH NO DATA, passes.
38 CREATE TABLE selinto_schema.tbl_nodata1 (a) AS
39 SELECT generate_series(1,3) WITH NO DATA;
40 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
41 CREATE TABLE selinto_schema.tbl_nodata2 (a) AS
42 SELECT generate_series(1,3) WITH NO DATA;
44 -------------------------------
45 ProjectSet (never executed)
46 -> Result (never executed)
49 -- EXECUTE and WITH DATA, passes.
50 PREPARE data_sel AS SELECT generate_series(1,3);
51 CREATE TABLE selinto_schema.tbl_withdata3 (a) AS
52 EXECUTE data_sel WITH DATA;
53 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
54 CREATE TABLE selinto_schema.tbl_withdata4 (a) AS
55 EXECUTE data_sel WITH DATA;
57 --------------------------------------
58 ProjectSet (actual rows=3 loops=1)
59 -> Result (actual rows=1 loops=1)
62 -- EXECUTE and WITH NO DATA, passes.
63 CREATE TABLE selinto_schema.tbl_nodata3 (a) AS
64 EXECUTE data_sel WITH NO DATA;
65 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF, BUFFERS OFF)
66 CREATE TABLE selinto_schema.tbl_nodata4 (a) AS
67 EXECUTE data_sel WITH NO DATA;
69 -------------------------------
70 ProjectSet (never executed)
71 -> Result (never executed)
74 RESET SESSION AUTHORIZATION;
75 ALTER DEFAULT PRIVILEGES FOR ROLE regress_selinto_user
76 GRANT INSERT ON TABLES TO regress_selinto_user;
77 SET SESSION AUTHORIZATION regress_selinto_user;
78 RESET SESSION AUTHORIZATION;
80 DROP SCHEMA selinto_schema CASCADE;
81 NOTICE: drop cascades to 8 other objects
82 DETAIL: drop cascades to table selinto_schema.tbl_withdata1
83 drop cascades to table selinto_schema.tbl_withdata2
84 drop cascades to table selinto_schema.tbl_nodata1
85 drop cascades to table selinto_schema.tbl_nodata2
86 drop cascades to table selinto_schema.tbl_withdata3
87 drop cascades to table selinto_schema.tbl_withdata4
88 drop cascades to table selinto_schema.tbl_nodata3
89 drop cascades to table selinto_schema.tbl_nodata4
90 DROP USER regress_selinto_user;
91 -- Tests for WITH NO DATA and column name consistency
92 CREATE TABLE ctas_base (i int, j int);
93 INSERT INTO ctas_base VALUES (1, 2);
94 CREATE TABLE ctas_nodata (ii, jj, kk) AS SELECT i, j FROM ctas_base; -- Error
95 ERROR: too many column names were specified
96 CREATE TABLE ctas_nodata (ii, jj, kk) AS SELECT i, j FROM ctas_base WITH NO DATA; -- Error
97 ERROR: too many column names were specified
98 CREATE TABLE ctas_nodata (ii, jj) AS SELECT i, j FROM ctas_base; -- OK
99 CREATE TABLE ctas_nodata_2 (ii, jj) AS SELECT i, j FROM ctas_base WITH NO DATA; -- OK
100 CREATE TABLE ctas_nodata_3 (ii) AS SELECT i, j FROM ctas_base; -- OK
101 CREATE TABLE ctas_nodata_4 (ii) AS SELECT i, j FROM ctas_base WITH NO DATA; -- OK
102 SELECT * FROM ctas_nodata;
108 SELECT * FROM ctas_nodata_2;
113 SELECT * FROM ctas_nodata_3;
119 SELECT * FROM ctas_nodata_4;
124 DROP TABLE ctas_base;
125 DROP TABLE ctas_nodata;
126 DROP TABLE ctas_nodata_2;
127 DROP TABLE ctas_nodata_3;
128 DROP TABLE ctas_nodata_4;
130 -- CREATE TABLE AS/SELECT INTO as last command in a SQL function
131 -- have been known to cause problems
133 CREATE FUNCTION make_table() RETURNS VOID
135 CREATE TABLE created_table AS SELECT * FROM int8_tbl;
143 SELECT * FROM created_table;
145 ------------------+-------------------
147 123 | 4567890123456789
148 4567890123456789 | 123
149 4567890123456789 | 4567890123456789
150 4567890123456789 | -4567890123456789
153 -- Try EXPLAIN ANALYZE SELECT INTO and EXPLAIN ANALYZE CREATE TABLE AS
154 -- WITH NO DATA, but hide the outputs since they won't be stable.
157 EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl';
158 EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM int8_tbl WITH NO DATA';
160 DROP TABLE created_table;
161 DROP TABLE easi, easi2;
163 -- Disallowed uses of SELECT ... INTO. All should fail
165 DECLARE foo CURSOR FOR SELECT 1 INTO int4_tbl;
166 ERROR: SELECT ... INTO is not allowed here
167 LINE 1: DECLARE foo CURSOR FOR SELECT 1 INTO int4_tbl;
169 COPY (SELECT 1 INTO frak UNION SELECT 2) TO 'blob';
170 ERROR: COPY (SELECT INTO) is not supported
171 SELECT * FROM (SELECT 1 INTO f) bar;
172 ERROR: SELECT ... INTO is not allowed here
173 LINE 1: SELECT * FROM (SELECT 1 INTO f) bar;
175 CREATE VIEW foo AS SELECT 1 INTO int4_tbl;
176 ERROR: views must not contain SELECT INTO
177 INSERT INTO int4_tbl SELECT 1 INTO f;
178 ERROR: SELECT ... INTO is not allowed here
179 LINE 1: INSERT INTO int4_tbl SELECT 1 INTO f;
181 -- Test CREATE TABLE AS ... IF NOT EXISTS
182 CREATE TABLE ctas_ine_tbl AS SELECT 1;
183 CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0; -- error
184 ERROR: relation "ctas_ine_tbl" already exists
185 CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0; -- ok
186 NOTICE: relation "ctas_ine_tbl" already exists, skipping
187 CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- error
188 ERROR: relation "ctas_ine_tbl" already exists
189 CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- ok
190 NOTICE: relation "ctas_ine_tbl" already exists, skipping
191 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
192 CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0; -- error
193 ERROR: relation "ctas_ine_tbl" already exists
194 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
195 CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0; -- ok
196 NOTICE: relation "ctas_ine_tbl" already exists, skipping
201 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
202 CREATE TABLE ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- error
203 ERROR: relation "ctas_ine_tbl" already exists
204 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
205 CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS SELECT 1 / 0 WITH NO DATA; -- ok
206 NOTICE: relation "ctas_ine_tbl" already exists, skipping
211 PREPARE ctas_ine_query AS SELECT 1 / 0;
212 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
213 CREATE TABLE ctas_ine_tbl AS EXECUTE ctas_ine_query; -- error
214 ERROR: relation "ctas_ine_tbl" already exists
215 EXPLAIN (ANALYZE, COSTS OFF, SUMMARY OFF, TIMING OFF)
216 CREATE TABLE IF NOT EXISTS ctas_ine_tbl AS EXECUTE ctas_ine_query; -- ok
217 NOTICE: relation "ctas_ine_tbl" already exists, skipping
222 DROP TABLE ctas_ine_tbl;