706
706
create view v2a as select * from (tt2 join tt3 using (b,c) join tt4 using (b)) j;
707
707
create view v3 as select * from tt2 join tt3 using (b,c) full join tt4 using (b);
708
708
select pg_get_viewdef('v1', true);
710
---------------------------
716
JOIN tt3 USING (b, c);
710
-----------------------------
716
JOIN tt3 USING (b, c);
719
719
select pg_get_viewdef('v1a', true);
721
------------------------------
727
JOIN tt3 USING (b, c)) j;
721
--------------------------------
727
JOIN tt3 USING (b, c)) j;
730
730
select pg_get_viewdef('v2', true);
732
--------------------------
740
JOIN tt3 USING (b, c)+
732
----------------------------
740
JOIN tt3 USING (b, c)+
744
744
select pg_get_viewdef('v2a', true);
746
---------------------------
754
JOIN tt3 USING (b, c) +
755
JOIN tt4 USING (b)) j;
746
-----------------------------
754
JOIN tt3 USING (b, c) +
755
JOIN tt4 USING (b)) j;
758
758
select pg_get_viewdef('v3', true);
760
-----------------------------
768
JOIN tt3 USING (b, c) +
769
FULL JOIN tt4 USING (b);
760
-------------------------------
768
JOIN tt3 USING (b, c) +
769
FULL JOIN tt4 USING (b);
772
772
alter table tt2 add column d int;
773
773
alter table tt2 add column e int;
774
774
select pg_get_viewdef('v1', true);
776
---------------------------
782
JOIN tt3 USING (b, c);
776
-----------------------------
782
JOIN tt3 USING (b, c);
785
785
select pg_get_viewdef('v1a', true);
787
------------------------------
793
JOIN tt3 USING (b, c)) j;
787
--------------------------------
793
JOIN tt3 USING (b, c)) j;
796
796
select pg_get_viewdef('v2', true);
798
--------------------------
806
JOIN tt3 USING (b, c)+
798
----------------------------
806
JOIN tt3 USING (b, c)+
810
810
select pg_get_viewdef('v2a', true);
812
---------------------------
820
JOIN tt3 USING (b, c) +
821
JOIN tt4 USING (b)) j;
812
-----------------------------
820
JOIN tt3 USING (b, c) +
821
JOIN tt4 USING (b)) j;
824
824
select pg_get_viewdef('v3', true);
826
-----------------------------
834
JOIN tt3 USING (b, c) +
835
FULL JOIN tt4 USING (b);
826
-------------------------------
834
JOIN tt3 USING (b, c) +
835
FULL JOIN tt4 USING (b);
838
838
alter table tt3 rename c to d;
839
839
select pg_get_viewdef('v1', true);
841
-----------------------------------------
847
JOIN tt3 tt3(ax, b, c) USING (b, c);
841
-------------------------------------------
847
JOIN tt3 tt3(ax, b, c) USING (b, c);
850
850
select pg_get_viewdef('v1a', true);
852
--------------------------------------------
858
JOIN tt3 tt3(ax, b, c) USING (b, c)) j;
852
----------------------------------------------
858
JOIN tt3 tt3(ax, b, c) USING (b, c)) j;
861
861
select pg_get_viewdef('v2', true);
863
----------------------------------------
871
JOIN tt3 tt3(ax, b, c) USING (b, c)+
863
------------------------------------------
871
JOIN tt3 tt3(ax, b, c) USING (b, c)+
875
875
select pg_get_viewdef('v2a', true);
877
----------------------------------------
885
JOIN tt3 tt3(ax, b, c) USING (b, c)+
886
JOIN tt4 USING (b)) j;
877
------------------------------------------
885
JOIN tt3 tt3(ax, b, c) USING (b, c)+
886
JOIN tt4 USING (b)) j;
889
889
select pg_get_viewdef('v3', true);
891
----------------------------------------
899
JOIN tt3 tt3(ax, b, c) USING (b, c)+
900
FULL JOIN tt4 USING (b);
891
------------------------------------------
899
JOIN tt3 tt3(ax, b, c) USING (b, c)+
900
FULL JOIN tt4 USING (b);
903
903
alter table tt3 add column c int;
904
904
alter table tt3 add column e int;
905
905
select pg_get_viewdef('v1', true);
907
-------------------------------------------------
913
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
907
---------------------------------------------------
913
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
916
916
select pg_get_viewdef('v1a', true);
918
---------------------------------------------------------------------------------
924
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, d, e, ax, c_1, e_1);
918
-----------------------------------------------------------------------------------
924
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, d, e, ax, c_1, e_1);
927
927
select pg_get_viewdef('v2', true);
929
------------------------------------------------
937
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
929
--------------------------------------------------
937
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
941
941
select pg_get_viewdef('v2a', true);
943
---------------------------------------------------------------
951
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
952
JOIN tt4 USING (b)) j(b, c, a, d, e, ax, c_1, e_1, ay, q);
943
-----------------------------------------------------------------
951
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
952
JOIN tt4 USING (b)) j(b, c, a, d, e, ax, c_1, e_1, ay, q);
955
955
select pg_get_viewdef('v3', true);
957
------------------------------------------------
965
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
966
FULL JOIN tt4 USING (b);
957
--------------------------------------------------
965
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
966
FULL JOIN tt4 USING (b);
969
969
alter table tt2 drop column d;
970
970
select pg_get_viewdef('v1', true);
972
-------------------------------------------------
978
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
972
---------------------------------------------------
978
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
981
981
select pg_get_viewdef('v1a', true);
983
------------------------------------------------------------------------------
989
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, e, ax, c_1, e_1);
983
--------------------------------------------------------------------------------
989
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, e, ax, c_1, e_1);
992
992
select pg_get_viewdef('v2', true);
994
------------------------------------------------
1002
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
994
--------------------------------------------------
1002
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1006
1006
select pg_get_viewdef('v2a', true);
1008
------------------------------------------------------------
1016
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
1017
JOIN tt4 USING (b)) j(b, c, a, e, ax, c_1, e_1, ay, q);
1008
--------------------------------------------------------------
1016
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
1017
JOIN tt4 USING (b)) j(b, c, a, e, ax, c_1, e_1, ay, q);
1020
1020
select pg_get_viewdef('v3', true);
1022
------------------------------------------------
1030
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1031
FULL JOIN tt4 USING (b);
1022
--------------------------------------------------
1030
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
1031
FULL JOIN tt4 USING (b);
1034
1034
create table tt5 (a int, b int);
1035
1035
create table tt6 (c int, d int);
1036
1036
create view vv1 as select * from (tt5 cross join tt6) j(aa,bb,cc,dd);
1037
1037
select pg_get_viewdef('vv1', true);
1039
--------------------------------------
1045
CROSS JOIN tt6) j(aa, bb, cc, dd);
1048
alter table tt5 add column c int;
1049
select pg_get_viewdef('vv1', true);
1051
1039
-----------------------------------------
1175
1175
alter table tt7 drop column zz;
1176
1176
alter table tt8 add column z2 int;
1177
1177
select pg_get_viewdef('vv2', true);
1179
--------------------------------------------------------
1185
FROM ( VALUES (1,2,3,4,5)) v(a, b, c, d, e)+
1193
FULL JOIN tt8 USING (x), +
1194
tt8 tt8x(x_1, z, z2);
1179
------------------------------------------------
1185
FROM ( VALUES (1,2,3,4,5)) v(a, b, c, d, e)+
1193
FULL JOIN tt8 USING (x), +
1194
tt8 tt8x(x_1, z, z2);
1197
1197
select pg_get_viewdef('vv3', true);
1199
-------------------------------------------------------------
1206
FROM ( VALUES (1,2,3,4,5,6)) v(a, b, c, x, e, f)+
1215
FULL JOIN tt8 USING (x), +
1216
tt7 tt7x(x_1, y, z) +
1217
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1);
1199
-----------------------------------------------------
1206
FROM ( VALUES (1,2,3,4,5,6)) v(a, b, c, x, e, f)+
1215
FULL JOIN tt8 USING (x), +
1216
tt7 tt7x(x_1, y, z) +
1217
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1);
1220
1220
select pg_get_viewdef('vv4', true);
1222
------------------------------------------------------------------
1230
FROM ( VALUES (1,2,3,4,5,6,7)) v(a, b, c, x, e, f, g)+
1240
FULL JOIN tt8 USING (x), +
1241
tt7 tt7x(x_1, y, z) +
1242
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1) +
1243
FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1);
1222
----------------------------------------------------------
1230
FROM ( VALUES (1,2,3,4,5,6,7)) v(a, b, c, x, e, f, g)+
1240
FULL JOIN tt8 USING (x), +
1241
tt7 tt7x(x_1, y, z) +
1242
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1) +
1243
FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1);
1246
1246
-- Implicit coercions in a JOIN USING create issues similar to FULL JOIN
1278
1278
create table tt10 (x int, z int);
1279
1279
create view vv5 as select x,y,z from tt9 join tt10 using(x);
1280
1280
select pg_get_viewdef('vv5', true);
1282
-------------------------
1287
JOIN tt10 USING (x);
1282
---------------------------
1287
JOIN tt10 USING (x);
1290
1290
alter table tt9 drop column xx;
1291
1291
select pg_get_viewdef('vv5', true);
1293
-------------------------
1298
JOIN tt10 USING (x);
1293
---------------------------
1298
JOIN tt10 USING (x);
1302
-- Another corner case is that we might add a column to a table below a
1303
-- JOIN USING, and thereby make the USING column name ambiguous
1305
create table tt11 (x int, y int);
1306
create table tt12 (x int, z int);
1307
create table tt13 (z int, q int);
1308
create view vv6 as select x,y,z,q from
1309
(tt11 join tt12 using(x)) join tt13 using(z);
1310
select pg_get_viewdef('vv6', true);
1312
---------------------------
1318
JOIN tt12 USING (x) +
1319
JOIN tt13 USING (z);
1322
alter table tt11 add column z int;
1323
select pg_get_viewdef('vv6', true);
1325
------------------------------
1330
FROM tt11 tt11(x, y, z_1)+
1331
JOIN tt12 USING (x) +
1332
JOIN tt13 USING (z);
1336
-- Check some cases involving dropped columns in a function's rowtype result
1338
create table tt14t (f1 text, f2 text, f3 text, f4 text);
1339
insert into tt14t values('foo', 'bar', 'baz', 'quux');
1340
alter table tt14t drop column f2;
1341
create function tt14f() returns setof tt14t as
1346
for rec1 in select * from tt14t
1353
create view tt14v as select t.* from tt14f() t;
1354
select pg_get_viewdef('tt14v', true);
1356
--------------------------------
1360
FROM tt14f() t(f1, f3, f4);
1363
select * from tt14v;
1369
-- this perhaps should be rejected, but it isn't:
1370
alter table tt14t drop column f3;
1371
-- f3 is still in the view but will read as nulls
1372
select pg_get_viewdef('tt14v', true);
1374
--------------------------------
1378
FROM tt14f() t(f1, f3, f4);
1381
select * from tt14v;
1301
1387
-- clean up all the random objects we made above