Fix indentation of JOIN clauses in rule/view dumps.

The code attempted to outdent JOIN clauses further left than the parent
FROM keyword, which was odd in any case, and led to inconsistent formatting
since in simple cases the clauses couldn't be moved any further left than
that.  And it left a permanent decrement of the indentation level, causing
subsequent lines to be much further left than they should be (again, this
couldn't be seen in simple cases for lack of indentation to give up).

After a little experimentation I chose to make it indent JOIN keywords
two spaces from the parent FROM, which is one space more than the join's
lefthand input in cases where that appears on a different line from FROM.

Back-patch to 9.3.  This is a purely cosmetic change, and the bug is quite
old, so that may seem arbitrary; but we are going to be making some other
changes to the indentation behavior in both HEAD and 9.3, so it seems
reasonable to include this in 9.3 too.  I committed this one first because
its effects are more visible in the regression test results as they
currently stand than they will be later.
This commit is contained in:
Tom Lane 2014-04-30 12:01:19 -04:00
parent 5358bfdc98
commit d166eed302
4 changed files with 404 additions and 402 deletions

View File

@ -68,8 +68,7 @@
/* Indent counts */
#define PRETTYINDENT_STD 8
#define PRETTYINDENT_JOIN 13
#define PRETTYINDENT_JOIN_ON (PRETTYINDENT_JOIN-PRETTYINDENT_STD)
#define PRETTYINDENT_JOIN 4
#define PRETTYINDENT_VAR 4
/* Pretty flags */
@ -8378,27 +8377,32 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
case JOIN_INNER:
if (j->quals)
appendContextKeyword(context, " JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
else
appendContextKeyword(context, " CROSS JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 1);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_LEFT:
appendContextKeyword(context, " LEFT JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_FULL:
appendContextKeyword(context, " FULL JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_RIGHT:
appendContextKeyword(context, " RIGHT JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
default:
elog(ERROR, "unrecognized join type: %d",
@ -8411,8 +8415,6 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
if (need_paren_on_right)
appendStringInfoChar(buf, ')');
context->indentLevel -= PRETTYINDENT_JOIN_ON;
if (j->usingClause)
{
ListCell *lc;

View File

@ -706,346 +706,334 @@ create view v2 as select * from tt2 join tt3 using (b,c) join tt4 using (b);
create view v2a as select * from (tt2 join tt3 using (b,c) join tt4 using (b)) j;
create view v3 as select * from tt2 join tt3 using (b,c) full join tt4 using (b);
select pg_get_viewdef('v1', true);
pg_get_viewdef
---------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 USING (b, c);
pg_get_viewdef
-----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 USING (b, c);
(1 row)
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 USING (b, c)) j;
pg_get_viewdef
--------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 USING (b, c)) j;
(1 row)
select pg_get_viewdef('v2', true);
pg_get_viewdef
--------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c)+
JOIN tt4 USING (b);
pg_get_viewdef
----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c)+
JOIN tt4 USING (b);
(1 row)
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 USING (b, c) +
JOIN tt4 USING (b)) j;
pg_get_viewdef
-----------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 USING (b, c) +
JOIN tt4 USING (b)) j;
(1 row)
select pg_get_viewdef('v3', true);
pg_get_viewdef
-----------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c) +
FULL JOIN tt4 USING (b);
pg_get_viewdef
-------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c) +
FULL JOIN tt4 USING (b);
(1 row)
alter table tt2 add column d int;
alter table tt2 add column e int;
select pg_get_viewdef('v1', true);
pg_get_viewdef
---------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 USING (b, c);
pg_get_viewdef
-----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 USING (b, c);
(1 row)
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 USING (b, c)) j;
pg_get_viewdef
--------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 USING (b, c)) j;
(1 row)
select pg_get_viewdef('v2', true);
pg_get_viewdef
--------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c)+
JOIN tt4 USING (b);
pg_get_viewdef
----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c)+
JOIN tt4 USING (b);
(1 row)
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 USING (b, c) +
JOIN tt4 USING (b)) j;
pg_get_viewdef
-----------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 USING (b, c) +
JOIN tt4 USING (b)) j;
(1 row)
select pg_get_viewdef('v3', true);
pg_get_viewdef
-----------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c) +
FULL JOIN tt4 USING (b);
pg_get_viewdef
-------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 USING (b, c) +
FULL JOIN tt4 USING (b);
(1 row)
alter table tt3 rename c to d;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-----------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c);
pg_get_viewdef
-------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c);
(1 row)
select pg_get_viewdef('v1a', true);
pg_get_viewdef
--------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)) j;
pg_get_viewdef
----------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)) j;
(1 row)
select pg_get_viewdef('v2', true);
pg_get_viewdef
----------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
JOIN tt4 USING (b);
pg_get_viewdef
------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
JOIN tt4 USING (b);
(1 row)
select pg_get_viewdef('v2a', true);
pg_get_viewdef
----------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
JOIN tt4 USING (b)) j;
pg_get_viewdef
------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
JOIN tt4 USING (b)) j;
(1 row)
select pg_get_viewdef('v3', true);
pg_get_viewdef
----------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
FULL JOIN tt4 USING (b);
pg_get_viewdef
------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c) USING (b, c)+
FULL JOIN tt4 USING (b);
(1 row)
alter table tt3 add column c int;
alter table tt3 add column e int;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
pg_get_viewdef
---------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
(1 row)
select pg_get_viewdef('v1a', true);
pg_get_viewdef
---------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, d, e, ax, c_1, e_1);
pg_get_viewdef
-----------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, d, e, ax, c_1, e_1);
(1 row)
select pg_get_viewdef('v2', true);
pg_get_viewdef
------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
JOIN tt4 USING (b);
pg_get_viewdef
--------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
JOIN tt4 USING (b);
(1 row)
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
JOIN tt4 USING (b)) j(b, c, a, d, e, ax, c_1, e_1, ay, q);
pg_get_viewdef
-----------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
JOIN tt4 USING (b)) j(b, c, a, d, e, ax, c_1, e_1, ay, q);
(1 row)
select pg_get_viewdef('v3', true);
pg_get_viewdef
------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
FULL JOIN tt4 USING (b);
pg_get_viewdef
--------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
FULL JOIN tt4 USING (b);
(1 row)
alter table tt2 drop column d;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
pg_get_viewdef
---------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c);
(1 row)
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, e, ax, c_1, e_1);
pg_get_viewdef
--------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)) j(b, c, a, e, ax, c_1, e_1);
(1 row)
select pg_get_viewdef('v2', true);
pg_get_viewdef
------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
JOIN tt4 USING (b);
pg_get_viewdef
--------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
JOIN tt4 USING (b);
(1 row)
select pg_get_viewdef('v2a', true);
pg_get_viewdef
------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
JOIN tt4 USING (b)) j(b, c, a, e, ax, c_1, e_1, ay, q);
pg_get_viewdef
--------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
j.ax, +
j.ay, +
j.q +
FROM (tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c) +
JOIN tt4 USING (b)) j(b, c, a, e, ax, c_1, e_1, ay, q);
(1 row)
select pg_get_viewdef('v3', true);
pg_get_viewdef
------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
FULL JOIN tt4 USING (b);
pg_get_viewdef
--------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
tt3.ax, +
tt4.ay, +
tt4.q +
FROM tt2 +
JOIN tt3 tt3(ax, b, c, c_1, e) USING (b, c)+
FULL JOIN tt4 USING (b);
(1 row)
create table tt5 (a int, b int);
create table tt6 (c int, d int);
create view vv1 as select * from (tt5 cross join tt6) j(aa,bb,cc,dd);
select pg_get_viewdef('vv1', true);
pg_get_viewdef
--------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, cc, dd);
(1 row)
alter table tt5 add column c int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
-----------------------------------------
@ -1054,22 +1042,10 @@ select pg_get_viewdef('vv1', true);
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, c, cc, dd);
CROSS JOIN tt6) j(aa, bb, cc, dd);
(1 row)
alter table tt5 add column cc int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
-----------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, c, cc_1, cc, dd);
(1 row)
alter table tt5 drop column c;
alter table tt5 add column c int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
--------------------------------------------
@ -1078,7 +1054,31 @@ select pg_get_viewdef('vv1', true);
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, cc_1, cc, dd);
CROSS JOIN tt6) j(aa, bb, c, cc, dd);
(1 row)
alter table tt5 add column cc int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
--------------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, c, cc_1, cc, dd);
(1 row)
alter table tt5 drop column c;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
-----------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
j.dd +
FROM (tt5 +
CROSS JOIN tt6) j(aa, bb, cc_1, cc, dd);
(1 row)
-- Unnamed FULL JOIN USING is lots of fun too
@ -1105,8 +1105,8 @@ select pg_get_viewdef('vv2', true);
tt8x.x_1 AS d, +
tt8x.z AS e +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt8 tt8x(x_1, z);
FULL JOIN tt8 USING (x), +
tt8 tt8x(x_1, z);
(1 row)
create view vv3 as
@ -1133,9 +1133,9 @@ select pg_get_viewdef('vv3', true);
tt7x.y AS e, +
tt8x.z AS f +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y) +
FULL JOIN tt8 tt8x(x_1, z) USING (x_1);
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y) +
FULL JOIN tt8 tt8x(x_1, z) USING (x_1);
(1 row)
create view vv4 as
@ -1164,10 +1164,10 @@ select pg_get_viewdef('vv4', true);
tt8x.z AS f, +
tt8y.z AS g +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y) +
FULL JOIN tt8 tt8x(x_1, z) USING (x_1) +
FULL JOIN tt8 tt8y(x_1, z) USING (x_1);
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y) +
FULL JOIN tt8 tt8x(x_1, z) USING (x_1) +
FULL JOIN tt8 tt8y(x_1, z) USING (x_1);
(1 row)
alter table tt7 add column zz int;
@ -1190,8 +1190,8 @@ select pg_get_viewdef('vv2', true);
tt8x.x_1 AS d, +
tt8x.z AS e +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt8 tt8x(x_1, z, z2);
FULL JOIN tt8 USING (x), +
tt8 tt8x(x_1, z, z2);
(1 row)
select pg_get_viewdef('vv3', true);
@ -1212,9 +1212,9 @@ select pg_get_viewdef('vv3', true);
tt7x.y AS e, +
tt8x.z AS f +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y, z) +
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1);
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y, z) +
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1);
(1 row)
select pg_get_viewdef('vv4', true);
@ -1237,10 +1237,10 @@ select pg_get_viewdef('vv4', true);
tt8x.z AS f, +
tt8y.z AS g +
FROM tt7 +
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y, z) +
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1) +
FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1);
FULL JOIN tt8 USING (x), +
tt7 tt7x(x_1, y, z) +
FULL JOIN tt8 tt8x(x_1, z, z2) USING (x_1) +
FULL JOIN tt8 tt8y(x_1, z, z2) USING (x_1);
(1 row)
-- Implicit coercions in a JOIN USING create issues similar to FULL JOIN
@ -1267,8 +1267,8 @@ select pg_get_viewdef('vv2a', true);
tt8ax.x_1 AS d, +
tt8ax.z AS e +
FROM tt7a +
LEFT JOIN tt8a USING (x), +
tt8a tt8ax(x_1, z);
LEFT JOIN tt8a USING (x), +
tt8a tt8ax(x_1, z);
(1 row)
--
@ -1278,24 +1278,24 @@ create table tt9 (x int, xx int, y int);
create table tt10 (x int, z int);
create view vv5 as select x,y,z from tt9 join tt10 using(x);
select pg_get_viewdef('vv5', true);
pg_get_viewdef
-------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +
FROM tt9 +
JOIN tt10 USING (x);
pg_get_viewdef
---------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +
FROM tt9 +
JOIN tt10 USING (x);
(1 row)
alter table tt9 drop column xx;
select pg_get_viewdef('vv5', true);
pg_get_viewdef
-------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +
FROM tt9 +
JOIN tt10 USING (x);
pg_get_viewdef
---------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +
FROM tt9 +
JOIN tt10 USING (x);
(1 row)
-- clean up all the random objects we made above

View File

@ -85,14 +85,14 @@ select * from vw_ord;
(1 row)
select definition from pg_views where viewname='vw_ord';
definition
-------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +
z.ord +
FROM (( VALUES (1)) v(n) +
JOIN foot(1) WITH ORDINALITY z(a, b, ord) ON ((v.n = z.ord)));
definition
---------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +
z.ord +
FROM (( VALUES (1)) v(n) +
JOIN foot(1) WITH ORDINALITY z(a, b, ord) ON ((v.n = z.ord)));
(1 row)
drop view vw_ord;
@ -112,16 +112,16 @@ select * from vw_ord;
(1 row)
select definition from pg_views where viewname='vw_ord';
definition
---------------------------------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +
z.c, +
z.d, +
z.ord +
FROM (( VALUES (1)) v(n) +
JOIN ROWS FROM(foot(1), foot(2)) WITH ORDINALITY z(a, b, c, d, ord) ON ((v.n = z.ord)));
definition
-----------------------------------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +
z.c, +
z.d, +
z.ord +
FROM (( VALUES (1)) v(n) +
JOIN ROWS FROM(foot(1), foot(2)) WITH ORDINALITY z(a, b, c, d, ord) ON ((v.n = z.ord)));
(1 row)
drop view vw_ord;

View File

@ -1294,13 +1294,13 @@ pg_available_extension_versions| SELECT e.name,
e.requires,
e.comment
FROM (pg_available_extension_versions() e(name, version, superuser, relocatable, schema, requires, comment)
LEFT JOIN pg_extension x ON (((e.name = x.extname) AND (e.version = x.extversion))));
LEFT JOIN pg_extension x ON (((e.name = x.extname) AND (e.version = x.extversion))));
pg_available_extensions| SELECT e.name,
e.default_version,
x.extversion AS installed_version,
e.comment
FROM (pg_available_extensions() e(name, default_version, comment)
LEFT JOIN pg_extension x ON ((e.name = x.extname)));
LEFT JOIN pg_extension x ON ((e.name = x.extname)));
pg_cursors| SELECT c.name,
c.statement,
c.is_holdable,
@ -1321,10 +1321,10 @@ pg_indexes| SELECT n.nspname AS schemaname,
t.spcname AS tablespace,
pg_get_indexdef(i.oid) AS indexdef
FROM ((((pg_index x
JOIN pg_class c ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = i.reltablespace)))
JOIN pg_class c ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = i.reltablespace)))
WHERE ((c.relkind = ANY (ARRAY['r'::"char", 'm'::"char"])) AND (i.relkind = 'i'::"char"));
pg_locks| SELECT l.locktype,
l.database,
@ -1350,8 +1350,8 @@ pg_matviews| SELECT n.nspname AS schemaname,
c.relispopulated AS ispopulated,
pg_get_viewdef(c.oid) AS definition
FROM ((pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
WHERE (c.relkind = 'm'::"char");
pg_prepared_statements| SELECT p.name,
p.statement,
@ -1365,8 +1365,8 @@ pg_prepared_xacts| SELECT p.transaction,
u.rolname AS owner,
d.datname AS database
FROM ((pg_prepared_xact() p(transaction, gid, prepared, ownerid, dbid)
LEFT JOIN pg_authid u ON ((p.ownerid = u.oid)))
LEFT JOIN pg_database d ON ((p.dbid = d.oid)));
LEFT JOIN pg_authid u ON ((p.ownerid = u.oid)))
LEFT JOIN pg_database d ON ((p.dbid = d.oid)));
pg_replication_slots| SELECT l.slot_name,
l.plugin,
l.slot_type,
@ -1377,7 +1377,7 @@ pg_replication_slots| SELECT l.slot_name,
l.catalog_xmin,
l.restart_lsn
FROM (pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, active, xmin, catalog_xmin, restart_lsn)
LEFT JOIN pg_database d ON ((l.datoid = d.oid)));
LEFT JOIN pg_database d ON ((l.datoid = d.oid)));
pg_roles| SELECT pg_authid.rolname,
pg_authid.rolsuper,
pg_authid.rolinherit,
@ -1392,14 +1392,14 @@ pg_roles| SELECT pg_authid.rolname,
s.setconfig AS rolconfig,
pg_authid.oid
FROM (pg_authid
LEFT JOIN pg_db_role_setting s ON (((pg_authid.oid = s.setrole) AND (s.setdatabase = (0)::oid))));
LEFT JOIN pg_db_role_setting s ON (((pg_authid.oid = s.setrole) AND (s.setdatabase = (0)::oid))));
pg_rules| SELECT n.nspname AS schemaname,
c.relname AS tablename,
r.rulename,
pg_get_ruledef(r.oid) AS definition
FROM ((pg_rewrite r
JOIN pg_class c ON ((c.oid = r.ev_class)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
JOIN pg_class c ON ((c.oid = r.ev_class)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (r.rulename <> '_RETURN'::name);
pg_seclabels| ( ( ( ( ( ( ( ( ( SELECT l.objoid,
l.classoid,
@ -1420,9 +1420,9 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM ((pg_seclabel l
JOIN pg_class rel ON (((l.classoid = rel.tableoid) AND (l.objoid = rel.oid))))
JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid)))
WHERE (l.objsubid = 0)
JOIN pg_class rel ON (((l.classoid = rel.tableoid) AND (l.objoid = rel.oid))))
JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid)))
WHERE (l.objsubid = 0)
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1437,10 +1437,10 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (((pg_seclabel l
JOIN pg_class rel ON (((l.classoid = rel.tableoid) AND (l.objoid = rel.oid))))
JOIN pg_attribute att ON (((rel.oid = att.attrelid) AND (l.objsubid = att.attnum))))
JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid)))
WHERE (l.objsubid <> 0))
JOIN pg_class rel ON (((l.classoid = rel.tableoid) AND (l.objoid = rel.oid))))
JOIN pg_attribute att ON (((rel.oid = att.attrelid) AND (l.objsubid = att.attnum))))
JOIN pg_namespace nsp ON ((rel.relnamespace = nsp.oid)))
WHERE (l.objsubid <> 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1459,9 +1459,9 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM ((pg_seclabel l
JOIN pg_proc pro ON (((l.classoid = pro.tableoid) AND (l.objoid = pro.oid))))
JOIN pg_namespace nsp ON ((pro.pronamespace = nsp.oid)))
WHERE (l.objsubid = 0))
JOIN pg_proc pro ON (((l.classoid = pro.tableoid) AND (l.objoid = pro.oid))))
JOIN pg_namespace nsp ON ((pro.pronamespace = nsp.oid)))
WHERE (l.objsubid = 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1478,9 +1478,9 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM ((pg_seclabel l
JOIN pg_type typ ON (((l.classoid = typ.tableoid) AND (l.objoid = typ.oid))))
JOIN pg_namespace nsp ON ((typ.typnamespace = nsp.oid)))
WHERE (l.objsubid = 0))
JOIN pg_type typ ON (((l.classoid = typ.tableoid) AND (l.objoid = typ.oid))))
JOIN pg_namespace nsp ON ((typ.typnamespace = nsp.oid)))
WHERE (l.objsubid = 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1491,8 +1491,8 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_seclabel l
JOIN pg_largeobject_metadata lom ON ((l.objoid = lom.oid)))
WHERE ((l.classoid = ('pg_largeobject'::regclass)::oid) AND (l.objsubid = 0)))
JOIN pg_largeobject_metadata lom ON ((l.objoid = lom.oid)))
WHERE ((l.classoid = ('pg_largeobject'::regclass)::oid) AND (l.objsubid = 0)))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1503,8 +1503,8 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_seclabel l
JOIN pg_language lan ON (((l.classoid = lan.tableoid) AND (l.objoid = lan.oid))))
WHERE (l.objsubid = 0))
JOIN pg_language lan ON (((l.classoid = lan.tableoid) AND (l.objoid = lan.oid))))
WHERE (l.objsubid = 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1515,8 +1515,8 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_seclabel l
JOIN pg_namespace nsp ON (((l.classoid = nsp.tableoid) AND (l.objoid = nsp.oid))))
WHERE (l.objsubid = 0))
JOIN pg_namespace nsp ON (((l.classoid = nsp.tableoid) AND (l.objoid = nsp.oid))))
WHERE (l.objsubid = 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1527,8 +1527,8 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_seclabel l
JOIN pg_event_trigger evt ON (((l.classoid = evt.tableoid) AND (l.objoid = evt.oid))))
WHERE (l.objsubid = 0))
JOIN pg_event_trigger evt ON (((l.classoid = evt.tableoid) AND (l.objoid = evt.oid))))
WHERE (l.objsubid = 0))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1539,7 +1539,7 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_shseclabel l
JOIN pg_database dat ON (((l.classoid = dat.tableoid) AND (l.objoid = dat.oid)))))
JOIN pg_database dat ON (((l.classoid = dat.tableoid) AND (l.objoid = dat.oid)))))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1550,7 +1550,7 @@ pg_seclabels| ( ( ( ( ( ( (
l.provider,
l.label
FROM (pg_shseclabel l
JOIN pg_tablespace spc ON (((l.classoid = spc.tableoid) AND (l.objoid = spc.oid)))))
JOIN pg_tablespace spc ON (((l.classoid = spc.tableoid) AND (l.objoid = spc.oid)))))
UNION ALL
SELECT l.objoid,
l.classoid,
@ -1561,7 +1561,7 @@ UNION ALL
l.provider,
l.label
FROM (pg_shseclabel l
JOIN pg_authid rol ON (((l.classoid = rol.tableoid) AND (l.objoid = rol.oid))));
JOIN pg_authid rol ON (((l.classoid = rol.tableoid) AND (l.objoid = rol.oid))));
pg_settings| SELECT a.name,
a.setting,
a.unit,
@ -1589,7 +1589,7 @@ pg_shadow| SELECT pg_authid.rolname AS usename,
(pg_authid.rolvaliduntil)::abstime AS valuntil,
s.setconfig AS useconfig
FROM (pg_authid
LEFT JOIN pg_db_role_setting s ON (((pg_authid.oid = s.setrole) AND (s.setdatabase = (0)::oid))))
LEFT JOIN pg_db_role_setting s ON (((pg_authid.oid = s.setrole) AND (s.setdatabase = (0)::oid))))
WHERE pg_authid.rolcanlogin;
pg_stat_activity| SELECT s.datid,
d.datname,
@ -1622,9 +1622,9 @@ pg_stat_all_indexes| SELECT c.oid AS relid,
pg_stat_get_tuples_returned(i.oid) AS idx_tup_read,
pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch
FROM (((pg_class c
JOIN pg_index x ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
JOIN pg_index x ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]));
pg_stat_all_tables| SELECT c.oid AS relid,
n.nspname AS schemaname,
@ -1649,8 +1649,8 @@ pg_stat_all_tables| SELECT c.oid AS relid,
pg_stat_get_analyze_count(c.oid) AS analyze_count,
pg_stat_get_autoanalyze_count(c.oid) AS autoanalyze_count
FROM ((pg_class c
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]))
GROUP BY c.oid, n.nspname, c.relname;
pg_stat_archiver| SELECT s.archived_count,
@ -1761,7 +1761,7 @@ pg_stat_user_functions| SELECT p.oid AS funcid,
pg_stat_get_function_total_time(p.oid) AS total_time,
pg_stat_get_function_self_time(p.oid) AS self_time
FROM (pg_proc p
LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace)))
LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace)))
WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_function_calls(p.oid) IS NOT NULL));
pg_stat_user_indexes| SELECT pg_stat_all_indexes.relid,
pg_stat_all_indexes.indexrelid,
@ -1809,8 +1809,8 @@ pg_stat_xact_all_tables| SELECT c.oid AS relid,
pg_stat_get_xact_tuples_deleted(c.oid) AS n_tup_del,
pg_stat_get_xact_tuples_hot_updated(c.oid) AS n_tup_hot_upd
FROM ((pg_class c
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]))
GROUP BY c.oid, n.nspname, c.relname;
pg_stat_xact_sys_tables| SELECT pg_stat_xact_all_tables.relid,
@ -1833,7 +1833,7 @@ pg_stat_xact_user_functions| SELECT p.oid AS funcid,
pg_stat_get_xact_function_total_time(p.oid) AS total_time,
pg_stat_get_xact_function_self_time(p.oid) AS self_time
FROM (pg_proc p
LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace)))
LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace)))
WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_xact_function_calls(p.oid) IS NOT NULL));
pg_stat_xact_user_tables| SELECT pg_stat_xact_all_tables.relid,
pg_stat_xact_all_tables.schemaname,
@ -1856,9 +1856,9 @@ pg_statio_all_indexes| SELECT c.oid AS relid,
(pg_stat_get_blocks_fetched(i.oid) - pg_stat_get_blocks_hit(i.oid)) AS idx_blks_read,
pg_stat_get_blocks_hit(i.oid) AS idx_blks_hit
FROM (((pg_class c
JOIN pg_index x ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
JOIN pg_index x ON ((c.oid = x.indrelid)))
JOIN pg_class i ON ((i.oid = x.indexrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]));
pg_statio_all_sequences| SELECT c.oid AS relid,
n.nspname AS schemaname,
@ -1866,7 +1866,7 @@ pg_statio_all_sequences| SELECT c.oid AS relid,
(pg_stat_get_blocks_fetched(c.oid) - pg_stat_get_blocks_hit(c.oid)) AS blks_read,
pg_stat_get_blocks_hit(c.oid) AS blks_hit
FROM (pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = 'S'::"char");
pg_statio_all_tables| SELECT c.oid AS relid,
n.nspname AS schemaname,
@ -1880,10 +1880,10 @@ pg_statio_all_tables| SELECT c.oid AS relid,
(sum((pg_stat_get_blocks_fetched(x.indexrelid) - pg_stat_get_blocks_hit(x.indexrelid))))::bigint AS tidx_blks_read,
(sum(pg_stat_get_blocks_hit(x.indexrelid)))::bigint AS tidx_blks_hit
FROM ((((pg_class c
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_class t ON ((c.reltoastrelid = t.oid)))
LEFT JOIN pg_index x ON ((t.oid = x.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_index i ON ((c.oid = i.indrelid)))
LEFT JOIN pg_class t ON ((c.reltoastrelid = t.oid)))
LEFT JOIN pg_index x ON ((t.oid = x.indrelid)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char", 'm'::"char"]))
GROUP BY c.oid, n.nspname, c.relname, t.oid, x.indrelid;
pg_statio_sys_indexes| SELECT pg_statio_all_indexes.relid,
@ -2008,9 +2008,9 @@ pg_stats| SELECT n.nspname AS schemaname,
ELSE NULL::real[]
END AS elem_count_histogram
FROM (((pg_statistic s
JOIN pg_class c ON ((c.oid = s.starelid)))
JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
JOIN pg_class c ON ((c.oid = s.starelid)))
JOIN pg_attribute a ON (((c.oid = a.attrelid) AND (a.attnum = s.staattnum))))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE ((NOT a.attisdropped) AND has_column_privilege(c.oid, a.attnum, 'select'::text));
pg_tables| SELECT n.nspname AS schemaname,
c.relname AS tablename,
@ -2020,8 +2020,8 @@ pg_tables| SELECT n.nspname AS schemaname,
c.relhasrules AS hasrules,
c.relhastriggers AS hastriggers
FROM ((pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
WHERE (c.relkind = 'r'::"char");
pg_timezone_abbrevs| SELECT pg_timezone_abbrevs.abbrev,
pg_timezone_abbrevs.utc_offset,
@ -2055,14 +2055,14 @@ pg_user_mappings| SELECT u.oid AS umid,
ELSE NULL::text[]
END AS umoptions
FROM ((pg_user_mapping u
LEFT JOIN pg_authid a ON ((a.oid = u.umuser)))
JOIN pg_foreign_server s ON ((u.umserver = s.oid)));
LEFT JOIN pg_authid a ON ((a.oid = u.umuser)))
JOIN pg_foreign_server s ON ((u.umserver = s.oid)));
pg_views| SELECT n.nspname AS schemaname,
c.relname AS viewname,
pg_get_userbyid(c.relowner) AS viewowner,
pg_get_viewdef(c.oid) AS definition
FROM (pg_class c
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
WHERE (c.relkind = 'v'::"char");
rtest_v1| SELECT rtest_t1.a,
rtest_t1.b