3 -- Virtual class definitions
4 -- (this also tests the query rewrite system)
7 SELECT r.name, r.thepath, c.cname AS cname
8 FROM ONLY road r, real_city c
9 WHERE c.outline ## r.thepath;
11 SELECT ih.name, ih.thepath,
12 interpt_pp(ih.thepath, r.thepath) AS exit
13 FROM ihighway ih, ramp r
14 WHERE ih.thepath ## r.thepath;
16 SELECT name, age, location, 12*salary AS annualsal
19 COMMENT ON VIEW noview IS 'no view';
20 ERROR: relation "noview" does not exist
21 COMMENT ON VIEW toyemp IS 'is a view';
22 COMMENT ON VIEW toyemp IS NULL;
23 -- These views are left around mainly to exercise special cases in pg_dump.
24 CREATE TABLE view_base_table (key int PRIMARY KEY, data varchar(20));
25 CREATE VIEW key_dependent_view AS
26 SELECT * FROM view_base_table GROUP BY key;
27 ALTER TABLE view_base_table DROP CONSTRAINT view_base_table_pkey; -- fails
28 ERROR: cannot drop constraint view_base_table_pkey on table view_base_table because other objects depend on it
29 DETAIL: view key_dependent_view depends on constraint view_base_table_pkey on table view_base_table
30 HINT: Use DROP ... CASCADE to drop the dependent objects too.
31 CREATE VIEW key_dependent_view_no_cols AS
32 SELECT FROM view_base_table GROUP BY key HAVING length(data) > 0;
34 -- CREATE OR REPLACE VIEW
36 CREATE TABLE viewtest_tbl (a int, b int);
37 COPY viewtest_tbl FROM stdin;
38 CREATE OR REPLACE VIEW viewtest AS
39 SELECT * FROM viewtest_tbl;
40 CREATE OR REPLACE VIEW viewtest AS
41 SELECT * FROM viewtest_tbl WHERE a > 10;
42 SELECT * FROM viewtest;
49 CREATE OR REPLACE VIEW viewtest AS
50 SELECT a, b FROM viewtest_tbl WHERE a > 5 ORDER BY b DESC;
51 SELECT * FROM viewtest;
60 CREATE OR REPLACE VIEW viewtest AS
61 SELECT a FROM viewtest_tbl WHERE a <> 20;
62 ERROR: cannot drop columns from view
64 CREATE OR REPLACE VIEW viewtest AS
65 SELECT 1, * FROM viewtest_tbl;
66 ERROR: cannot change name of view column "a" to "?column?"
67 HINT: Use ALTER VIEW ... RENAME COLUMN ... to change name of view column instead.
69 CREATE OR REPLACE VIEW viewtest AS
70 SELECT a, b::numeric FROM viewtest_tbl;
71 ERROR: cannot change data type of view column "b" from integer to numeric
73 CREATE OR REPLACE VIEW viewtest AS
74 SELECT a, b, 0 AS c FROM viewtest_tbl;
76 DROP TABLE viewtest_tbl;
77 -- tests for temporary views
78 CREATE SCHEMA temp_view_test
79 CREATE TABLE base_table (a int, id int)
80 CREATE TABLE base_table2 (a int, id int);
81 SET search_path TO temp_view_test, public;
82 CREATE TEMPORARY TABLE temp_table (a int, id int);
83 -- should be created in temp_view_test schema
84 CREATE VIEW v1 AS SELECT * FROM base_table;
85 -- should be created in temp object schema
86 CREATE VIEW v1_temp AS SELECT * FROM temp_table;
87 NOTICE: view "v1_temp" will be a temporary view
88 -- should be created in temp object schema
89 CREATE TEMP VIEW v2_temp AS SELECT * FROM base_table;
90 -- should be created in temp_views schema
91 CREATE VIEW temp_view_test.v2 AS SELECT * FROM base_table;
93 CREATE VIEW temp_view_test.v3_temp AS SELECT * FROM temp_table;
94 NOTICE: view "v3_temp" will be a temporary view
95 ERROR: cannot create temporary relation in non-temporary schema
97 CREATE SCHEMA test_view_schema
98 CREATE TEMP VIEW testview AS SELECT 1;
99 ERROR: cannot create temporary relation in non-temporary schema
100 -- joins: if any of the join relations are temporary, the view
101 -- should also be temporary
102 -- should be non-temp
104 SELECT t1.a AS t1_a, t2.a AS t2_a
105 FROM base_table t1, base_table2 t2
107 -- should be temp (one join rel is temp)
108 CREATE VIEW v4_temp AS
109 SELECT t1.a AS t1_a, t2.a AS t2_a
110 FROM base_table t1, temp_table t2
112 NOTICE: view "v4_temp" will be a temporary view
114 CREATE VIEW v5_temp AS
115 SELECT t1.a AS t1_a, t2.a AS t2_a, t3.a AS t3_a
116 FROM base_table t1, base_table2 t2, temp_table t3
117 WHERE t1.id = t2.id and t2.id = t3.id;
118 NOTICE: view "v5_temp" will be a temporary view
120 CREATE VIEW v4 AS SELECT * FROM base_table WHERE id IN (SELECT id FROM base_table2);
121 CREATE VIEW v5 AS SELECT t1.id, t2.a FROM base_table t1, (SELECT * FROM base_table2) t2;
122 CREATE VIEW v6 AS SELECT * FROM base_table WHERE EXISTS (SELECT 1 FROM base_table2);
123 CREATE VIEW v7 AS SELECT * FROM base_table WHERE NOT EXISTS (SELECT 1 FROM base_table2);
124 CREATE VIEW v8 AS SELECT * FROM base_table WHERE EXISTS (SELECT 1);
125 CREATE VIEW v6_temp AS SELECT * FROM base_table WHERE id IN (SELECT id FROM temp_table);
126 NOTICE: view "v6_temp" will be a temporary view
127 CREATE VIEW v7_temp AS SELECT t1.id, t2.a FROM base_table t1, (SELECT * FROM temp_table) t2;
128 NOTICE: view "v7_temp" will be a temporary view
129 CREATE VIEW v8_temp AS SELECT * FROM base_table WHERE EXISTS (SELECT 1 FROM temp_table);
130 NOTICE: view "v8_temp" will be a temporary view
131 CREATE VIEW v9_temp AS SELECT * FROM base_table WHERE NOT EXISTS (SELECT 1 FROM temp_table);
132 NOTICE: view "v9_temp" will be a temporary view
133 -- a view should also be temporary if it references a temporary view
134 CREATE VIEW v10_temp AS SELECT * FROM v7_temp;
135 NOTICE: view "v10_temp" will be a temporary view
136 CREATE VIEW v11_temp AS SELECT t1.id, t2.a FROM base_table t1, v10_temp t2;
137 NOTICE: view "v11_temp" will be a temporary view
138 CREATE VIEW v12_temp AS SELECT true FROM v11_temp;
139 NOTICE: view "v12_temp" will be a temporary view
140 -- a view should also be temporary if it references a temporary sequence
141 CREATE SEQUENCE seq1;
142 CREATE TEMPORARY SEQUENCE seq1_temp;
143 CREATE VIEW v9 AS SELECT seq1.is_called FROM seq1;
144 CREATE VIEW v13_temp AS SELECT seq1_temp.is_called FROM seq1_temp;
145 NOTICE: view "v13_temp" will be a temporary view
146 SELECT relname FROM pg_class
147 WHERE relname LIKE 'v_'
148 AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'temp_view_test')
163 SELECT relname FROM pg_class
164 WHERE relname LIKE 'v%'
165 AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname LIKE 'pg_temp%')
183 CREATE SCHEMA testviewschm2;
184 SET search_path TO testviewschm2, public;
185 CREATE TABLE t1 (num int, name text);
186 CREATE TABLE t2 (num2 int, value text);
187 CREATE TEMP TABLE tt (num2 int, value text);
188 CREATE VIEW nontemp1 AS SELECT * FROM t1 CROSS JOIN t2;
189 CREATE VIEW temporal1 AS SELECT * FROM t1 CROSS JOIN tt;
190 NOTICE: view "temporal1" will be a temporary view
191 CREATE VIEW nontemp2 AS SELECT * FROM t1 INNER JOIN t2 ON t1.num = t2.num2;
192 CREATE VIEW temporal2 AS SELECT * FROM t1 INNER JOIN tt ON t1.num = tt.num2;
193 NOTICE: view "temporal2" will be a temporary view
194 CREATE VIEW nontemp3 AS SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num2;
195 CREATE VIEW temporal3 AS SELECT * FROM t1 LEFT JOIN tt ON t1.num = tt.num2;
196 NOTICE: view "temporal3" will be a temporary view
197 CREATE VIEW nontemp4 AS SELECT * FROM t1 LEFT JOIN t2 ON t1.num = t2.num2 AND t2.value = 'xxx';
198 CREATE VIEW temporal4 AS SELECT * FROM t1 LEFT JOIN tt ON t1.num = tt.num2 AND tt.value = 'xxx';
199 NOTICE: view "temporal4" will be a temporary view
200 SELECT relname FROM pg_class
201 WHERE relname LIKE 'nontemp%'
202 AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'testviewschm2')
212 SELECT relname FROM pg_class
213 WHERE relname LIKE 'temporal%'
214 AND relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname LIKE 'pg_temp%')
224 CREATE TABLE tbl1 ( a int, b int);
225 CREATE TABLE tbl2 (c int, d int);
226 CREATE TABLE tbl3 (e int, f int);
227 CREATE TABLE tbl4 (g int, h int);
228 CREATE TEMP TABLE tmptbl (i int, j int);
229 --Should be in testviewschm2
230 CREATE VIEW pubview AS SELECT * FROM tbl1 WHERE tbl1.a
231 BETWEEN (SELECT d FROM tbl2 WHERE c = 1) AND (SELECT e FROM tbl3 WHERE f = 2)
232 AND EXISTS (SELECT g FROM tbl4 LEFT JOIN tbl3 ON tbl4.h = tbl3.f);
233 SELECT count(*) FROM pg_class where relname = 'pubview'
234 AND relnamespace IN (SELECT OID FROM pg_namespace WHERE nspname = 'testviewschm2');
240 --Should be in temp object schema
241 CREATE VIEW mytempview AS SELECT * FROM tbl1 WHERE tbl1.a
242 BETWEEN (SELECT d FROM tbl2 WHERE c = 1) AND (SELECT e FROM tbl3 WHERE f = 2)
243 AND EXISTS (SELECT g FROM tbl4 LEFT JOIN tbl3 ON tbl4.h = tbl3.f)
244 AND NOT EXISTS (SELECT g FROM tbl4 LEFT JOIN tmptbl ON tbl4.h = tmptbl.j);
245 NOTICE: view "mytempview" will be a temporary view
246 SELECT count(*) FROM pg_class where relname LIKE 'mytempview'
247 And relnamespace IN (SELECT OID FROM pg_namespace WHERE nspname LIKE 'pg_temp%');
254 -- CREATE VIEW and WITH(...) clause
256 CREATE VIEW mysecview1
257 AS SELECT * FROM tbl1 WHERE a = 0;
258 CREATE VIEW mysecview2 WITH (security_barrier=true)
259 AS SELECT * FROM tbl1 WHERE a > 0;
260 CREATE VIEW mysecview3 WITH (security_barrier=false)
261 AS SELECT * FROM tbl1 WHERE a < 0;
262 CREATE VIEW mysecview4 WITH (security_barrier)
263 AS SELECT * FROM tbl1 WHERE a <> 0;
264 CREATE VIEW mysecview5 WITH (security_barrier=100) -- Error
265 AS SELECT * FROM tbl1 WHERE a > 100;
266 ERROR: invalid value for boolean option "security_barrier": 100
267 CREATE VIEW mysecview6 WITH (invalid_option) -- Error
268 AS SELECT * FROM tbl1 WHERE a < 100;
269 ERROR: unrecognized parameter "invalid_option"
270 SELECT relname, relkind, reloptions FROM pg_class
271 WHERE oid in ('mysecview1'::regclass, 'mysecview2'::regclass,
272 'mysecview3'::regclass, 'mysecview4'::regclass)
274 relname | relkind | reloptions
275 ------------+---------+--------------------------
277 mysecview2 | v | {security_barrier=true}
278 mysecview3 | v | {security_barrier=false}
279 mysecview4 | v | {security_barrier=true}
282 CREATE OR REPLACE VIEW mysecview1
283 AS SELECT * FROM tbl1 WHERE a = 256;
284 CREATE OR REPLACE VIEW mysecview2
285 AS SELECT * FROM tbl1 WHERE a > 256;
286 CREATE OR REPLACE VIEW mysecview3 WITH (security_barrier=true)
287 AS SELECT * FROM tbl1 WHERE a < 256;
288 CREATE OR REPLACE VIEW mysecview4 WITH (security_barrier=false)
289 AS SELECT * FROM tbl1 WHERE a <> 256;
290 SELECT relname, relkind, reloptions FROM pg_class
291 WHERE oid in ('mysecview1'::regclass, 'mysecview2'::regclass,
292 'mysecview3'::regclass, 'mysecview4'::regclass)
294 relname | relkind | reloptions
295 ------------+---------+--------------------------
298 mysecview3 | v | {security_barrier=true}
299 mysecview4 | v | {security_barrier=false}
302 -- Check that unknown literals are converted to "text" in CREATE VIEW,
303 -- so that we don't end up with unknown-type columns.
304 CREATE VIEW unspecified_types AS
305 SELECT 42 as i, 42.5 as num, 'foo' as u, 'foo'::unknown as u2, null as n;
306 \d+ unspecified_types
307 View "testviewschm2.unspecified_types"
308 Column | Type | Collation | Nullable | Default | Storage | Description
309 --------+---------+-----------+----------+---------+----------+-------------
310 i | integer | | | | plain |
311 num | numeric | | | | main |
312 u | text | | | | extended |
313 u2 | text | | | | extended |
314 n | text | | | | extended |
322 SELECT * FROM unspecified_types;
324 ----+------+-----+-----+---
325 42 | 42.5 | foo | foo |
328 -- This test checks that proper typmods are assigned in a multi-row VALUES
332 ('abc'::varchar(3), '0123456789', 42, 'abcd'::varchar(4)),
333 ('0123456789', 'abc'::varchar(3), 42.12, 'abc'::varchar(4))
336 View "testviewschm2.tt1"
337 Column | Type | Collation | Nullable | Default | Storage | Description
338 --------+----------------------+-----------+----------+---------+----------+-------------
339 a | character varying | | | | extended |
340 b | character varying | | | | extended |
341 c | numeric | | | | main |
342 d | character varying(4) | | | | extended |
348 FROM ( VALUES ('abc'::character varying(3),'0123456789'::character varying,42,'abcd'::character varying(4)), ('0123456789'::character varying,'abc'::character varying(3),42.12,'abc'::character varying(4))) vv(a, b, c, d);
352 ------------+------------+-------+------
353 abc | 0123456789 | 42 | abcd
354 0123456789 | abc | 42.12 | abc
357 SELECT a::varchar(3) FROM tt1;
365 -- Test view decompilation in the face of relation renaming conflicts
366 CREATE TABLE tt1 (f1 int, f2 int, f3 text);
367 CREATE TABLE tx1 (x1 int, x2 int, x3 text);
368 CREATE TABLE temp_view_test.tt1 (y1 int, f2 int, f3 text);
369 CREATE VIEW aliased_view_1 AS
371 where exists (select 1 from tx1 where tt1.f1 = tx1.x1);
372 CREATE VIEW aliased_view_2 AS
374 where exists (select 1 from tx1 where a1.f1 = tx1.x1);
375 CREATE VIEW aliased_view_3 AS
377 where exists (select 1 from tx1 a2 where tt1.f1 = a2.x1);
378 CREATE VIEW aliased_view_4 AS
379 select * from temp_view_test.tt1
380 where exists (select 1 from tt1 where temp_view_test.tt1.y1 = tt1.f1);
382 View "testviewschm2.aliased_view_1"
383 Column | Type | Collation | Nullable | Default | Storage | Description
384 --------+---------+-----------+----------+---------+----------+-------------
385 f1 | integer | | | | plain |
386 f2 | integer | | | | plain |
387 f3 | text | | | | extended |
393 WHERE (EXISTS ( SELECT 1
395 WHERE tt1.f1 = tx1.x1));
398 View "testviewschm2.aliased_view_2"
399 Column | Type | Collation | Nullable | Default | Storage | Description
400 --------+---------+-----------+----------+---------+----------+-------------
401 f1 | integer | | | | plain |
402 f2 | integer | | | | plain |
403 f3 | text | | | | extended |
409 WHERE (EXISTS ( SELECT 1
411 WHERE a1.f1 = tx1.x1));
414 View "testviewschm2.aliased_view_3"
415 Column | Type | Collation | Nullable | Default | Storage | Description
416 --------+---------+-----------+----------+---------+----------+-------------
417 f1 | integer | | | | plain |
418 f2 | integer | | | | plain |
419 f3 | text | | | | extended |
425 WHERE (EXISTS ( SELECT 1
427 WHERE tt1.f1 = a2.x1));
430 View "testviewschm2.aliased_view_4"
431 Column | Type | Collation | Nullable | Default | Storage | Description
432 --------+---------+-----------+----------+---------+----------+-------------
433 y1 | integer | | | | plain |
434 f2 | integer | | | | plain |
435 f3 | text | | | | extended |
440 FROM temp_view_test.tt1
441 WHERE (EXISTS ( SELECT 1
443 WHERE tt1.y1 = tt1_1.f1));
445 ALTER TABLE tx1 RENAME TO a1;
447 View "testviewschm2.aliased_view_1"
448 Column | Type | Collation | Nullable | Default | Storage | Description
449 --------+---------+-----------+----------+---------+----------+-------------
450 f1 | integer | | | | plain |
451 f2 | integer | | | | plain |
452 f3 | text | | | | extended |
458 WHERE (EXISTS ( SELECT 1
460 WHERE tt1.f1 = a1.x1));
463 View "testviewschm2.aliased_view_2"
464 Column | Type | Collation | Nullable | Default | Storage | Description
465 --------+---------+-----------+----------+---------+----------+-------------
466 f1 | integer | | | | plain |
467 f2 | integer | | | | plain |
468 f3 | text | | | | extended |
474 WHERE (EXISTS ( SELECT 1
476 WHERE a1.f1 = a1_1.x1));
479 View "testviewschm2.aliased_view_3"
480 Column | Type | Collation | Nullable | Default | Storage | Description
481 --------+---------+-----------+----------+---------+----------+-------------
482 f1 | integer | | | | plain |
483 f2 | integer | | | | plain |
484 f3 | text | | | | extended |
490 WHERE (EXISTS ( SELECT 1
492 WHERE tt1.f1 = a2.x1));
495 View "testviewschm2.aliased_view_4"
496 Column | Type | Collation | Nullable | Default | Storage | Description
497 --------+---------+-----------+----------+---------+----------+-------------
498 y1 | integer | | | | plain |
499 f2 | integer | | | | plain |
500 f3 | text | | | | extended |
505 FROM temp_view_test.tt1
506 WHERE (EXISTS ( SELECT 1
508 WHERE tt1.y1 = tt1_1.f1));
510 ALTER TABLE tt1 RENAME TO a2;
512 View "testviewschm2.aliased_view_1"
513 Column | Type | Collation | Nullable | Default | Storage | Description
514 --------+---------+-----------+----------+---------+----------+-------------
515 f1 | integer | | | | plain |
516 f2 | integer | | | | plain |
517 f3 | text | | | | extended |
523 WHERE (EXISTS ( SELECT 1
525 WHERE a2.f1 = a1.x1));
528 View "testviewschm2.aliased_view_2"
529 Column | Type | Collation | Nullable | Default | Storage | Description
530 --------+---------+-----------+----------+---------+----------+-------------
531 f1 | integer | | | | plain |
532 f2 | integer | | | | plain |
533 f3 | text | | | | extended |
539 WHERE (EXISTS ( SELECT 1
541 WHERE a1.f1 = a1_1.x1));
544 View "testviewschm2.aliased_view_3"
545 Column | Type | Collation | Nullable | Default | Storage | Description
546 --------+---------+-----------+----------+---------+----------+-------------
547 f1 | integer | | | | plain |
548 f2 | integer | | | | plain |
549 f3 | text | | | | extended |
555 WHERE (EXISTS ( SELECT 1
557 WHERE a2.f1 = a2_1.x1));
560 View "testviewschm2.aliased_view_4"
561 Column | Type | Collation | Nullable | Default | Storage | Description
562 --------+---------+-----------+----------+---------+----------+-------------
563 y1 | integer | | | | plain |
564 f2 | integer | | | | plain |
565 f3 | text | | | | extended |
570 FROM temp_view_test.tt1
571 WHERE (EXISTS ( SELECT 1
573 WHERE tt1.y1 = a2.f1));
575 ALTER TABLE a1 RENAME TO tt1;
577 View "testviewschm2.aliased_view_1"
578 Column | Type | Collation | Nullable | Default | Storage | Description
579 --------+---------+-----------+----------+---------+----------+-------------
580 f1 | integer | | | | plain |
581 f2 | integer | | | | plain |
582 f3 | text | | | | extended |
588 WHERE (EXISTS ( SELECT 1
590 WHERE a2.f1 = tt1.x1));
593 View "testviewschm2.aliased_view_2"
594 Column | Type | Collation | Nullable | Default | Storage | Description
595 --------+---------+-----------+----------+---------+----------+-------------
596 f1 | integer | | | | plain |
597 f2 | integer | | | | plain |
598 f3 | text | | | | extended |
604 WHERE (EXISTS ( SELECT 1
606 WHERE a1.f1 = tt1.x1));
609 View "testviewschm2.aliased_view_3"
610 Column | Type | Collation | Nullable | Default | Storage | Description
611 --------+---------+-----------+----------+---------+----------+-------------
612 f1 | integer | | | | plain |
613 f2 | integer | | | | plain |
614 f3 | text | | | | extended |
620 WHERE (EXISTS ( SELECT 1
622 WHERE a2.f1 = a2_1.x1));
625 View "testviewschm2.aliased_view_4"
626 Column | Type | Collation | Nullable | Default | Storage | Description
627 --------+---------+-----------+----------+---------+----------+-------------
628 y1 | integer | | | | plain |
629 f2 | integer | | | | plain |
630 f3 | text | | | | extended |
635 FROM temp_view_test.tt1
636 WHERE (EXISTS ( SELECT 1
638 WHERE tt1.y1 = a2.f1));
640 ALTER TABLE a2 RENAME TO tx1;
641 ALTER TABLE tx1 SET SCHEMA temp_view_test;
643 View "testviewschm2.aliased_view_1"
644 Column | Type | Collation | Nullable | Default | Storage | Description
645 --------+---------+-----------+----------+---------+----------+-------------
646 f1 | integer | | | | plain |
647 f2 | integer | | | | plain |
648 f3 | text | | | | extended |
653 FROM temp_view_test.tx1
654 WHERE (EXISTS ( SELECT 1
656 WHERE tx1.f1 = tt1.x1));
659 View "testviewschm2.aliased_view_2"
660 Column | Type | Collation | Nullable | Default | Storage | Description
661 --------+---------+-----------+----------+---------+----------+-------------
662 f1 | integer | | | | plain |
663 f2 | integer | | | | plain |
664 f3 | text | | | | extended |
669 FROM temp_view_test.tx1 a1
670 WHERE (EXISTS ( SELECT 1
672 WHERE a1.f1 = tt1.x1));
675 View "testviewschm2.aliased_view_3"
676 Column | Type | Collation | Nullable | Default | Storage | Description
677 --------+---------+-----------+----------+---------+----------+-------------
678 f1 | integer | | | | plain |
679 f2 | integer | | | | plain |
680 f3 | text | | | | extended |
685 FROM temp_view_test.tx1
686 WHERE (EXISTS ( SELECT 1
688 WHERE tx1.f1 = a2.x1));
691 View "testviewschm2.aliased_view_4"
692 Column | Type | Collation | Nullable | Default | Storage | Description
693 --------+---------+-----------+----------+---------+----------+-------------
694 y1 | integer | | | | plain |
695 f2 | integer | | | | plain |
696 f3 | text | | | | extended |
701 FROM temp_view_test.tt1
702 WHERE (EXISTS ( SELECT 1
703 FROM temp_view_test.tx1
704 WHERE tt1.y1 = tx1.f1));
706 ALTER TABLE temp_view_test.tt1 RENAME TO tmp1;
707 ALTER TABLE temp_view_test.tmp1 SET SCHEMA testviewschm2;
708 ALTER TABLE tmp1 RENAME TO tx1;
710 View "testviewschm2.aliased_view_1"
711 Column | Type | Collation | Nullable | Default | Storage | Description
712 --------+---------+-----------+----------+---------+----------+-------------
713 f1 | integer | | | | plain |
714 f2 | integer | | | | plain |
715 f3 | text | | | | extended |
720 FROM temp_view_test.tx1
721 WHERE (EXISTS ( SELECT 1
723 WHERE tx1.f1 = tt1.x1));
726 View "testviewschm2.aliased_view_2"
727 Column | Type | Collation | Nullable | Default | Storage | Description
728 --------+---------+-----------+----------+---------+----------+-------------
729 f1 | integer | | | | plain |
730 f2 | integer | | | | plain |
731 f3 | text | | | | extended |
736 FROM temp_view_test.tx1 a1
737 WHERE (EXISTS ( SELECT 1
739 WHERE a1.f1 = tt1.x1));
742 View "testviewschm2.aliased_view_3"
743 Column | Type | Collation | Nullable | Default | Storage | Description
744 --------+---------+-----------+----------+---------+----------+-------------
745 f1 | integer | | | | plain |
746 f2 | integer | | | | plain |
747 f3 | text | | | | extended |
752 FROM temp_view_test.tx1
753 WHERE (EXISTS ( SELECT 1
755 WHERE tx1.f1 = a2.x1));
758 View "testviewschm2.aliased_view_4"
759 Column | Type | Collation | Nullable | Default | Storage | Description
760 --------+---------+-----------+----------+---------+----------+-------------
761 y1 | integer | | | | plain |
762 f2 | integer | | | | plain |
763 f3 | text | | | | extended |
769 WHERE (EXISTS ( SELECT 1
770 FROM temp_view_test.tx1 tx1_1
771 WHERE tx1.y1 = tx1_1.f1));
773 -- Test aliasing of joins
774 create view view_of_joins as
776 (select * from (tbl1 cross join tbl2) same) ss,
777 (tbl3 cross join tbl4) same;
779 View "testviewschm2.view_of_joins"
780 Column | Type | Collation | Nullable | Default | Storage | Description
781 --------+---------+-----------+----------+---------+---------+-------------
782 a | integer | | | | plain |
783 b | integer | | | | plain |
784 c | integer | | | | plain |
785 d | integer | | | | plain |
786 e | integer | | | | plain |
787 f | integer | | | | plain |
788 g | integer | | | | plain |
789 h | integer | | | | plain |
799 FROM ( SELECT same_1.a,
804 CROSS JOIN tbl2) same_1) ss,
806 CROSS JOIN tbl4) same;
808 create table tbl1a (a int, c int);
809 create view view_of_joins_2a as select * from tbl1 join tbl1a using (a);
810 create view view_of_joins_2b as select * from tbl1 join tbl1a using (a) as x;
811 create view view_of_joins_2c as select * from (tbl1 join tbl1a using (a)) as y;
812 create view view_of_joins_2d as select * from (tbl1 join tbl1a using (a) as x) as y;
813 select pg_get_viewdef('view_of_joins_2a', true);
815 ----------------------------
820 JOIN tbl1a USING (a);
823 select pg_get_viewdef('view_of_joins_2b', true);
825 ---------------------------------
830 JOIN tbl1a USING (a) AS x;
833 select pg_get_viewdef('view_of_joins_2c', true);
835 -------------------------------
840 JOIN tbl1a USING (a)) y;
843 select pg_get_viewdef('view_of_joins_2d', true);
845 ------------------------------------
850 JOIN tbl1a USING (a) AS x) y;
853 -- Test view decompilation in the face of column addition/deletion/renaming
854 create table tt2 (a int, b int, c int);
855 create table tt3 (ax int8, b int2, c numeric);
856 create table tt4 (ay int, b int, q int);
857 create view v1 as select * from tt2 natural join tt3;
858 create view v1a as select * from (tt2 natural join tt3) j;
859 create view v2 as select * from tt2 join tt3 using (b,c) join tt4 using (b);
860 create view v2a as select * from (tt2 join tt3 using (b,c) join tt4 using (b)) j;
861 create view v3 as select * from tt2 join tt3 using (b,c) full join tt4 using (b);
862 select pg_get_viewdef('v1', true);
864 -----------------------------
870 JOIN tt3 USING (b, c);
873 select pg_get_viewdef('v1a', true);
875 --------------------------------
881 JOIN tt3 USING (b, c)) j;
884 select pg_get_viewdef('v2', true);
886 ----------------------------
894 JOIN tt3 USING (b, c)+
898 select pg_get_viewdef('v2a', true);
900 -----------------------------
908 JOIN tt3 USING (b, c) +
909 JOIN tt4 USING (b)) j;
912 select pg_get_viewdef('v3', true);
914 -------------------------------
922 JOIN tt3 USING (b, c) +
923 FULL JOIN tt4 USING (b);
926 alter table tt2 add column d int;
927 alter table tt2 add column e int;
928 select pg_get_viewdef('v1', true);
930 -----------------------------
936 JOIN tt3 USING (b, c);
939 select pg_get_viewdef('v1a', true);
941 --------------------------------
947 JOIN tt3 USING (b, c)) j;
950 select pg_get_viewdef('v2', true);
952 ----------------------------
960 JOIN tt3 USING (b, c)+
964 select pg_get_viewdef('v2a', true);
966 -----------------------------
974 JOIN tt3 USING (b, c) +
975 JOIN tt4 USING (b)) j;
978 select pg_get_viewdef('v3', true);
980 -------------------------------
988 JOIN tt3 USING (b, c) +
989 FULL JOIN tt4 USING (b);
992 alter table tt3 rename c to d;
993 select pg_get_viewdef('v1', true);
995 -------------------------------------------
1001 JOIN tt3 tt3(ax, b, c) USING (b, c);
1004 select pg_get_viewdef('v1a', true);
1006 ----------------------------------------------
1012 JOIN tt3 tt3(ax, b, c) USING (b, c)) j;
1015 select pg_get_viewdef('v2', true);
1017 ------------------------------------------
1025 JOIN tt3 tt3(ax, b, c) USING (b, c)+
1029 select pg_get_viewdef('v2a', true);
1031 ------------------------------------------
1039 JOIN tt3 tt3(ax, b, c) USING (b, c)+
1040 JOIN tt4 USING (b)) j;
1043 select pg_get_viewdef('v3', true);
1045 ------------------------------------------
1053 JOIN tt3 tt3(ax, b, c) USING (b, c)+
1054 FULL JOIN tt4 USING (b);
1057 alter table tt3 add column c int;
1058 alter table tt3 add column e int;
1059 select pg_get_viewdef('v1', true);
1061 ---------------------------------------------------
1067 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
1070 select pg_get_viewdef('v1a', true);
1072 -----------------------------------------------------------------------------------
1078 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, d, e, ax, c_1, e_1);
1081 select pg_get_viewdef('v2', true);
1083 --------------------------------------------------
1091 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1095 select pg_get_viewdef('v2a', true);
1097 -----------------------------------------------------------------
1105 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
1106 JOIN tt4 USING (b)) j(b, c, a, d, e, ax, c_1, e_1, ay, q);
1109 select pg_get_viewdef('v3', true);
1111 --------------------------------------------------
1119 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1120 FULL JOIN tt4 USING (b);
1123 alter table tt2 drop column d;
1124 select pg_get_viewdef('v1', true);
1126 ---------------------------------------------------
1132 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
1135 select pg_get_viewdef('v1a', true);
1137 --------------------------------------------------------------------------------
1143 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, e, ax, c_1, e_1);
1146 select pg_get_viewdef('v2', true);
1148 --------------------------------------------------
1156 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1160 select pg_get_viewdef('v2a', true);
1162 --------------------------------------------------------------
1170 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
1171 JOIN tt4 USING (b)) j(b, c, a, e, ax, c_1, e_1, ay, q);
1174 select pg_get_viewdef('v3', true);
1176 --------------------------------------------------
1184 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1185 FULL JOIN tt4 USING (b);
1188 create table tt5 (a int, b int);
1189 create table tt6 (c int, d int);
1190 create view vv1 as select * from (tt5 cross join tt6) j(aa,bb,cc,dd);
1191 select pg_get_viewdef('vv1', true);
1193 -----------------------------------------
1199 CROSS JOIN tt6) j(aa, bb, cc, dd);
1202 alter table tt5 add column c int;
1203 select pg_get_viewdef('vv1', true);
1205 --------------------------------------------
1211 CROSS JOIN tt6) j(aa, bb, c, cc, dd);
1214 alter table tt5 add column cc int;
1215 select pg_get_viewdef('vv1', true);
1217 --------------------------------------------------
1223 CROSS JOIN tt6) j(aa, bb, c, cc_1, cc, dd);
1226 alter table tt5 drop column c;
1227 select pg_get_viewdef('vv1', true);
1229 -----------------------------------------------
1235 CROSS JOIN tt6) j(aa, bb, cc_1, cc, dd);
1238 create view v4 as select * from v1;
1239 alter view v1 rename column a to x;
1240 select pg_get_viewdef('v1', true);
1242 ---------------------------------------------------
1248 JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
1251 select pg_get_viewdef('v4', true);
1261 -- Unnamed FULL JOIN USING is lots of fun too
1262 create table tt7 (x int, xx int, y int);
1263 alter table tt7 drop column xx;
1264 create table tt8 (x int, z int);
1266 select * from (values(1,2,3,4,5)) v(a,b,c,d,e)
1268 select * from tt7 full join tt8 using (x), tt8 tt8x;
1269 select pg_get_viewdef('vv2', true);
1271 ------------------------------------------------
1277 FROM ( VALUES (1,2,3,4,5)) v(a, b, c, d, e)+
1285 FULL JOIN tt8 USING (x), +
1290 select * from (values(1,2,3,4,5,6)) v(a,b,c,x,e,f)
1293 tt7 full join tt8 using (x),
1294 tt7 tt7x full join tt8 tt8x using (x);
1295 select pg_get_viewdef('vv3', true);
1297 -----------------------------------------------------
1304 FROM ( VALUES (1,2,3,4,5,6)) v(a, b, c, x, e, f)+
1313 FULL JOIN tt8 USING (x), +
1315 FULL JOIN tt8 tt8x(x_1, z) USING (x_1);
1319 select * from (values(1,2,3,4,5,6,7)) v(a,b,c,x,e,f,g)
1322 tt7 full join tt8 using (x),
1323 tt7 tt7x full join tt8 tt8x using (x) full join tt8 tt8y using (x);
1324 select pg_get_viewdef('vv4', true);
1326 ----------------------------------------------------------
1334 FROM ( VALUES (1,2,3,4,5,6,7)) v(a, b, c, x, e, f, g)+
1344 FULL JOIN tt8 USING (x), +
1346 FULL JOIN tt8 tt8x(x_1, z) USING (x_1) +
1347 FULL JOIN tt8 tt8y(x_1, z) USING (x_1);
1350 alter table tt7 add column zz int;
1351 alter table tt7 add column z int;
1352 alter table tt7 drop column zz;
1353 alter table tt8 add column z2 int;
1354 select pg_get_viewdef('vv2', true);
1356 ------------------------------------------------
1362 FROM ( VALUES (1,2,3,4,5)) v(a, b, c, d, e)+
1370 FULL JOIN tt8 USING (x), +
1371 tt8 tt8x(x_1, z, z2);
1374 select pg_get_viewdef('vv3', true);
1376 -----------------------------------------------------
1383 FROM ( VALUES (1,2,3,4,5,6)) v(a, b, c, x, e, f)+
1392 FULL JOIN tt8 USING (x), +
1393 tt7 tt7x(x_1, y, z) +
1394 FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1);
1397 select pg_get_viewdef('vv4', true);
1399 ----------------------------------------------------------
1407 FROM ( VALUES (1,2,3,4,5,6,7)) v(a, b, c, x, e, f, g)+
1417 FULL JOIN tt8 USING (x), +
1418 tt7 tt7x(x_1, y, z) +
1419 FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1) +
1420 FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1);
1423 -- Implicit coercions in a JOIN USING create issues similar to FULL JOIN
1424 create table tt7a (x date, xx int, y int);
1425 alter table tt7a drop column xx;
1426 create table tt8a (x timestamptz, z int);
1428 select * from (values(now(),2,3,now(),5)) v(a,b,c,d,e)
1430 select * from tt7a left join tt8a using (x), tt8a tt8ax;
1431 select pg_get_viewdef('vv2a', true);
1433 --------------------------------------------------------
1439 FROM ( VALUES (now(),2,3,now(),5)) v(a, b, c, d, e)+
1447 LEFT JOIN tt8a USING (x), +
1452 -- Also check dropping a column that existed when the view was made
1454 create table tt9 (x int, xx int, y int);
1455 create table tt10 (x int, z int);
1456 create view vv5 as select x,y,z from tt9 join tt10 using(x);
1457 select pg_get_viewdef('vv5', true);
1459 ---------------------------
1464 JOIN tt10 USING (x);
1467 alter table tt9 drop column xx;
1468 select pg_get_viewdef('vv5', true);
1470 ---------------------------
1475 JOIN tt10 USING (x);
1479 -- Another corner case is that we might add a column to a table below a
1480 -- JOIN USING, and thereby make the USING column name ambiguous
1482 create table tt11 (x int, y int);
1483 create table tt12 (x int, z int);
1484 create table tt13 (z int, q int);
1485 create view vv6 as select x,y,z,q from
1486 (tt11 join tt12 using(x)) join tt13 using(z);
1487 select pg_get_viewdef('vv6', true);
1489 ---------------------------
1495 JOIN tt12 USING (x) +
1496 JOIN tt13 USING (z);
1499 alter table tt11 add column z int;
1500 select pg_get_viewdef('vv6', true);
1502 ------------------------------
1507 FROM tt11 tt11(x, y, z_1)+
1508 JOIN tt12 USING (x) +
1509 JOIN tt13 USING (z);
1513 -- Check cases involving dropped/altered columns in a function's rowtype result
1515 create table tt14t (f1 text, f2 text, f3 text, f4 text);
1516 insert into tt14t values('foo', 'bar', 'baz', '42');
1517 alter table tt14t drop column f2;
1518 create function tt14f() returns setof tt14t as
1523 for rec1 in select * from tt14t
1530 create view tt14v as select t.* from tt14f() t;
1531 select pg_get_viewdef('tt14v', true);
1533 --------------------------------
1537 FROM tt14f() t(f1, f3, f4);
1540 select * from tt14v;
1547 -- this perhaps should be rejected, but it isn't:
1548 alter table tt14t drop column f3;
1549 -- f3 is still in the view ...
1550 select pg_get_viewdef('tt14v', true);
1552 --------------------------------
1556 FROM tt14f() t(f1, f3, f4);
1559 -- but will fail at execution
1560 select f1, f4 from tt14v;
1566 select * from tt14v;
1567 ERROR: attribute 3 of type record has been dropped
1570 -- this perhaps should be rejected, but it isn't:
1571 alter table tt14t alter column f4 type integer using f4::integer;
1572 -- f4 is still in the view ...
1573 select pg_get_viewdef('tt14v', true);
1575 --------------------------------
1579 FROM tt14f() t(f1, f3, f4);
1582 -- but will fail at execution
1583 select f1, f3 from tt14v;
1589 select * from tt14v;
1590 ERROR: attribute 4 of type record has wrong type
1591 DETAIL: Table has type integer, but query expects text.
1593 -- check display of whole-row variables in some corner cases
1594 create type nestedcomposite as (x int8_tbl);
1595 create view tt15v as select row(i)::nestedcomposite from int8_tbl i;
1596 select * from tt15v;
1598 ------------------------------------------
1600 ("(123,4567890123456789)")
1601 ("(4567890123456789,123)")
1602 ("(4567890123456789,4567890123456789)")
1603 ("(4567890123456789,-4567890123456789)")
1606 select pg_get_viewdef('tt15v', true);
1608 ------------------------------------------------------
1609 SELECT ROW(i.*::int8_tbl)::nestedcomposite AS "row"+
1613 select row(i.*::int8_tbl)::nestedcomposite from int8_tbl i;
1615 ------------------------------------------
1617 ("(123,4567890123456789)")
1618 ("(4567890123456789,123)")
1619 ("(4567890123456789,4567890123456789)")
1620 ("(4567890123456789,-4567890123456789)")
1623 create view tt16v as select * from int8_tbl i, lateral(values(i)) ss;
1624 select * from tt16v;
1626 ------------------+-------------------+--------------------------------------
1627 123 | 456 | (123,456)
1628 123 | 4567890123456789 | (123,4567890123456789)
1629 4567890123456789 | 123 | (4567890123456789,123)
1630 4567890123456789 | 4567890123456789 | (4567890123456789,4567890123456789)
1631 4567890123456789 | -4567890123456789 | (4567890123456789,-4567890123456789)
1634 select pg_get_viewdef('tt16v', true);
1636 -------------------------------------------
1641 LATERAL ( VALUES (i.*::int8_tbl)) ss;
1644 select * from int8_tbl i, lateral(values(i.*::int8_tbl)) ss;
1646 ------------------+-------------------+--------------------------------------
1647 123 | 456 | (123,456)
1648 123 | 4567890123456789 | (123,4567890123456789)
1649 4567890123456789 | 123 | (4567890123456789,123)
1650 4567890123456789 | 4567890123456789 | (4567890123456789,4567890123456789)
1651 4567890123456789 | -4567890123456789 | (4567890123456789,-4567890123456789)
1654 create view tt17v as select * from int8_tbl i where i in (values(i));
1655 select * from tt17v;
1657 ------------------+-------------------
1659 123 | 4567890123456789
1660 4567890123456789 | 123
1661 4567890123456789 | 4567890123456789
1662 4567890123456789 | -4567890123456789
1665 select pg_get_viewdef('tt17v', true);
1667 ---------------------------------------------
1671 WHERE (i.* IN ( VALUES (i.*::int8_tbl)));
1674 select * from int8_tbl i where i.* in (values(i.*::int8_tbl));
1676 ------------------+-------------------
1678 123 | 4567890123456789
1679 4567890123456789 | 123
1680 4567890123456789 | 4567890123456789
1681 4567890123456789 | -4567890123456789
1684 -- check unique-ification of overlength names
1685 create view tt18v as
1686 select * from int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy
1688 select * from int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz;
1689 NOTICE: identifier "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy" will be truncated to "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
1690 NOTICE: identifier "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz" will be truncated to "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
1691 select pg_get_viewdef('tt18v', true);
1693 -----------------------------------------------------------------------------------
1694 SELECT xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.q1, +
1695 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.q2 +
1696 FROM int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
1698 SELECT xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.q1, +
1699 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.q2 +
1700 FROM int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
1703 explain (costs off) select * from tt18v;
1705 --------------------------------------------------------------------------------------------
1707 -> Seq Scan on int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1708 -> Seq Scan on int8_tbl xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx_1
1711 -- check display of ScalarArrayOp with a sub-select
1712 select 'foo'::text = any(array['abc','def','foo']::text[]);
1718 select 'foo'::text = any((select array['abc','def','foo']::text[])); -- fail
1719 ERROR: operator does not exist: text = text[]
1720 LINE 1: select 'foo'::text = any((select array['abc','def','foo']::t...
1722 HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
1723 select 'foo'::text = any((select array['abc','def','foo']::text[])::text[]);
1729 create view tt19v as
1730 select 'foo'::text = any(array['abc','def','foo']::text[]) c1,
1731 'foo'::text = any((select array['abc','def','foo']::text[])::text[]) c2;
1732 select pg_get_viewdef('tt19v', true);
1734 ------------------------------------------------------------------------------------------------------------
1735 SELECT 'foo'::text = ANY (ARRAY['abc'::text, 'def'::text, 'foo'::text]) AS c1, +
1736 'foo'::text = ANY ((( SELECT ARRAY['abc'::text, 'def'::text, 'foo'::text] AS "array"))::text[]) AS c2;
1739 -- check display of assorted RTE_FUNCTION expressions
1740 create view tt20v as
1743 collation for ('x'::text) col,
1745 localtimestamp(3) as t,
1746 cast(1+2 as int4) as i4,
1747 cast(1+2 as int8) as i8;
1748 select pg_get_viewdef('tt20v', true);
1750 ---------------------------------------------
1757 FROM COALESCE(1, 2) c(c), +
1758 COLLATION FOR ('x'::text) col(col), +
1759 CURRENT_DATE d(d), +
1760 LOCALTIMESTAMP(3) t(t), +
1761 CAST(1 + 2 AS integer) i4(i4), +
1762 CAST((1 + 2)::bigint AS bigint) i8(i8);
1765 -- reverse-listing of various special function syntaxes required by SQL
1766 create view tt201v as
1768 extract(day from now()) as extr,
1769 (now(), '1 day'::interval) overlaps
1770 (current_timestamp(2), '1 day'::interval) as o,
1771 'foo' is normalized isn,
1772 'foo' is nfkc normalized isnn,
1773 normalize('foo') as n,
1774 normalize('foo', nfkd) as nfkd,
1775 overlay('foo' placing 'bar' from 2) as ovl,
1776 overlay('foo' placing 'bar' from 2 for 3) as ovl2,
1777 position('foo' in 'foobar') as p,
1778 substring('foo' from 2 for 3) as s,
1779 substring('foo' similar 'f' escape '#') as ss,
1780 substring('foo' from 'oo') as ssf, -- historically-permitted abuse
1781 trim(' ' from ' foo ') as bt,
1782 trim(leading ' ' from ' foo ') as lt,
1783 trim(trailing ' foo ') as rt,
1784 trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) as btb,
1785 trim(leading E'\\000'::bytea from E'\\000Tom\\000'::bytea) as ltb,
1786 trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea) as rtb;
1787 select pg_get_viewdef('tt201v', true);
1789 -----------------------------------------------------------------------------------------------
1790 SELECT EXTRACT(day FROM now()) AS extr, +
1791 ((now(), '@ 1 day'::interval) OVERLAPS (CURRENT_TIMESTAMP(2), '@ 1 day'::interval)) AS o,+
1792 (('foo'::text) IS NORMALIZED) AS isn, +
1793 (('foo'::text) IS NFKC NORMALIZED) AS isnn, +
1794 NORMALIZE('foo'::text) AS n, +
1795 NORMALIZE('foo'::text, NFKD) AS nfkd, +
1796 OVERLAY('foo'::text PLACING 'bar'::text FROM 2) AS ovl, +
1797 OVERLAY('foo'::text PLACING 'bar'::text FROM 2 FOR 3) AS ovl2, +
1798 POSITION(('foo'::text) IN ('foobar'::text)) AS p, +
1799 SUBSTRING('foo'::text FROM 2 FOR 3) AS s, +
1800 SUBSTRING('foo'::text SIMILAR 'f'::text ESCAPE '#'::text) AS ss, +
1801 "substring"('foo'::text, 'oo'::text) AS ssf, +
1802 TRIM(BOTH ' '::text FROM ' foo '::text) AS bt, +
1803 TRIM(LEADING ' '::text FROM ' foo '::text) AS lt, +
1804 TRIM(TRAILING FROM ' foo '::text) AS rt, +
1805 TRIM(BOTH '\x00'::bytea FROM '\x00546f6d00'::bytea) AS btb, +
1806 TRIM(LEADING '\x00'::bytea FROM '\x00546f6d00'::bytea) AS ltb, +
1807 TRIM(TRAILING '\x00'::bytea FROM '\x00546f6d00'::bytea) AS rtb;
1810 -- corner cases with empty join conditions
1811 create view tt21v as
1812 select * from tt5 natural inner join tt6;
1813 select pg_get_viewdef('tt21v', true);
1815 ----------------------
1825 create view tt22v as
1826 select * from tt5 natural left join tt6;
1827 select pg_get_viewdef('tt22v', true);
1829 -----------------------------
1836 LEFT JOIN tt6 ON TRUE;
1839 -- check handling of views with immediately-renamed columns
1840 create view tt23v (col_a, col_b) as
1841 select q1 as other_name1, q2 as other_name2 from int8_tbl
1844 select pg_get_viewdef('tt23v', true);
1846 -------------------------------
1847 SELECT int8_tbl.q1 AS col_a,+
1848 int8_tbl.q2 AS col_b +
1851 SELECT 42 AS col_a, +
1855 select pg_get_ruledef(oid, true) from pg_rewrite
1856 where ev_class = 'tt23v'::regclass and ev_type = '1';
1858 -----------------------------------------------------------------
1859 CREATE RULE "_RETURN" AS +
1860 ON SELECT TO tt23v DO INSTEAD SELECT int8_tbl.q1 AS col_a,+
1861 int8_tbl.q2 AS col_b +
1864 SELECT 42 AS col_a, +
1868 -- test extraction of FieldSelect field names (get_name_for_var_field)
1869 create view tt24v as
1870 with cte as materialized (select r from (values(1,2),(3,4)) r)
1871 select (r).column2 as col_a, (rr).column2 as col_b from
1872 cte join (select rr from (values(1,7),(3,8)) rr limit 2) ss
1873 on (r).column1 = (rr).column1;
1874 select pg_get_viewdef('tt24v', true);
1876 ------------------------------------------------------------
1877 WITH cte AS MATERIALIZED ( +
1878 SELECT r.*::record AS r +
1879 FROM ( VALUES (1,2), (3,4)) r +
1881 SELECT (cte.r).column2 AS col_a, +
1882 (ss.rr).column2 AS col_b +
1884 JOIN ( SELECT rr.*::record AS rr +
1885 FROM ( VALUES (1,7), (3,8)) rr +
1886 LIMIT 2) ss ON (cte.r).column1 = (ss.rr).column1;
1889 create view tt25v as
1890 with cte as materialized (select pg_get_keywords() k)
1891 select (k).word from cte;
1892 select pg_get_viewdef('tt25v', true);
1894 ----------------------------------------
1895 WITH cte AS MATERIALIZED ( +
1896 SELECT pg_get_keywords() AS k+
1898 SELECT (cte.k).word AS word +
1902 -- also check cases seen only in EXPLAIN
1903 explain (verbose, costs off)
1904 select * from tt24v;
1906 ------------------------------------------------------------------------------------------
1908 Output: (cte.r).column2, ((ROW("*VALUES*".column1, "*VALUES*".column2))).column2
1909 Hash Cond: (((ROW("*VALUES*".column1, "*VALUES*".column2))).column1 = (cte.r).column1)
1911 -> Values Scan on "*VALUES*_1"
1912 Output: ROW("*VALUES*_1".column1, "*VALUES*_1".column2)
1914 Output: (ROW("*VALUES*".column1, "*VALUES*".column2))
1915 -> Values Scan on "*VALUES*"
1916 Output: ROW("*VALUES*".column1, "*VALUES*".column2)
1923 explain (verbose, costs off)
1924 select (r).column2 from (select r from (values(1,2),(3,4)) r limit 1) ss;
1926 -------------------------------------------------------------------
1928 Output: (ss.r).column2
1930 Output: (ROW("*VALUES*".column1, "*VALUES*".column2))
1931 -> Values Scan on "*VALUES*"
1932 Output: ROW("*VALUES*".column1, "*VALUES*".column2)
1935 -- test pretty-print parenthesization rules, and SubLink deparsing
1936 create view tt26v as
1937 select x + y + z as c1,
1944 (x > y) AND (y > z OR x > z) as c8,
1945 (x > y) OR (y > z AND NOT (x > z)) as c9,
1946 (x,y) <> ALL (values(1,2),(3,4)) as c10,
1947 (x,y) <= ANY (values(1,2),(3,4)) as c11
1948 from (values(1,2,3)) v(x,y,z);
1949 select pg_get_viewdef('tt26v', true);
1951 --------------------------------------------------------
1952 SELECT v.x + v.y + v.z AS c1, +
1953 v.x * v.y + v.z AS c2, +
1954 v.x + v.y * v.z AS c3, +
1955 (v.x + v.y) * v.z AS c4, +
1956 v.x * (v.y + v.z) AS c5, +
1957 v.x + (v.y + v.z) AS c6, +
1958 v.x + (v.y # v.z) AS c7, +
1959 v.x > v.y AND (v.y > v.z OR v.x > v.z) AS c8, +
1960 v.x > v.y OR v.y > v.z AND NOT v.x > v.z AS c9, +
1961 ((v.x, v.y) <> ALL ( VALUES (1,2), (3,4))) AS c10,+
1962 ((v.x, v.y) <= ANY ( VALUES (1,2), (3,4))) AS c11 +
1963 FROM ( VALUES (1,2,3)) v(x, y, z);
1966 -- clean up all the random objects we made above
1967 DROP SCHEMA temp_view_test CASCADE;
1968 NOTICE: drop cascades to 27 other objects
1969 DETAIL: drop cascades to table temp_view_test.base_table
1970 drop cascades to view v2_temp
1971 drop cascades to view v4_temp
1972 drop cascades to view v6_temp
1973 drop cascades to view v7_temp
1974 drop cascades to view v10_temp
1975 drop cascades to view v8_temp
1976 drop cascades to view v9_temp
1977 drop cascades to view v11_temp
1978 drop cascades to view v12_temp
1979 drop cascades to table temp_view_test.base_table2
1980 drop cascades to view v5_temp
1981 drop cascades to view temp_view_test.v1
1982 drop cascades to view temp_view_test.v2
1983 drop cascades to view temp_view_test.v3
1984 drop cascades to view temp_view_test.v4
1985 drop cascades to view temp_view_test.v5
1986 drop cascades to view temp_view_test.v6
1987 drop cascades to view temp_view_test.v7
1988 drop cascades to view temp_view_test.v8
1989 drop cascades to sequence temp_view_test.seq1
1990 drop cascades to view temp_view_test.v9
1991 drop cascades to table temp_view_test.tx1
1992 drop cascades to view aliased_view_1
1993 drop cascades to view aliased_view_2
1994 drop cascades to view aliased_view_3
1995 drop cascades to view aliased_view_4
1996 DROP SCHEMA testviewschm2 CASCADE;
1997 NOTICE: drop cascades to 73 other objects
1998 DETAIL: drop cascades to table t1
1999 drop cascades to view temporal1
2000 drop cascades to view temporal2
2001 drop cascades to view temporal3
2002 drop cascades to view temporal4
2003 drop cascades to table t2
2004 drop cascades to view nontemp1
2005 drop cascades to view nontemp2
2006 drop cascades to view nontemp3
2007 drop cascades to view nontemp4
2008 drop cascades to table tbl1
2009 drop cascades to table tbl2
2010 drop cascades to table tbl3
2011 drop cascades to table tbl4
2012 drop cascades to view mytempview
2013 drop cascades to view pubview
2014 drop cascades to view mysecview1
2015 drop cascades to view mysecview2
2016 drop cascades to view mysecview3
2017 drop cascades to view mysecview4
2018 drop cascades to view unspecified_types
2019 drop cascades to table tt1
2020 drop cascades to table tx1
2021 drop cascades to view view_of_joins
2022 drop cascades to table tbl1a
2023 drop cascades to view view_of_joins_2a
2024 drop cascades to view view_of_joins_2b
2025 drop cascades to view view_of_joins_2c
2026 drop cascades to view view_of_joins_2d
2027 drop cascades to table tt2
2028 drop cascades to table tt3
2029 drop cascades to table tt4
2030 drop cascades to view v1
2031 drop cascades to view v1a
2032 drop cascades to view v2
2033 drop cascades to view v2a
2034 drop cascades to view v3
2035 drop cascades to table tt5
2036 drop cascades to table tt6
2037 drop cascades to view vv1
2038 drop cascades to view v4
2039 drop cascades to table tt7
2040 drop cascades to table tt8
2041 drop cascades to view vv2
2042 drop cascades to view vv3
2043 drop cascades to view vv4
2044 drop cascades to table tt7a
2045 drop cascades to table tt8a
2046 drop cascades to view vv2a
2047 drop cascades to table tt9
2048 drop cascades to table tt10
2049 drop cascades to view vv5
2050 drop cascades to table tt11
2051 drop cascades to table tt12
2052 drop cascades to table tt13
2053 drop cascades to view vv6
2054 drop cascades to table tt14t
2055 drop cascades to function tt14f()
2056 drop cascades to view tt14v
2057 drop cascades to type nestedcomposite
2058 drop cascades to view tt15v
2059 drop cascades to view tt16v
2060 drop cascades to view tt17v
2061 drop cascades to view tt18v
2062 drop cascades to view tt19v
2063 drop cascades to view tt20v
2064 drop cascades to view tt201v
2065 drop cascades to view tt21v
2066 drop cascades to view tt22v
2067 drop cascades to view tt23v
2068 drop cascades to view tt24v
2069 drop cascades to view tt25v
2070 drop cascades to view tt26v