Skip to content

Commit

Permalink
psql: Add information in \d+ about foreign partitions and child tables
Browse files Browse the repository at this point in the history
\d+ is already able to show if a partition or a child table is
"PARTITIONED" via its relkind, hence the addition of a keyword for
"FOREIGN" in the relation description is basically free.

Author: Ian Lawrence Barwick
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/CAB8KJ=iwzbEz2HR9EhNxQLVhMk2G_OYtQPJ9V=jWLadseggrOA@mail.gmail.com
  • Loading branch information
michaelpq committed Nov 8, 2022
1 parent 28cc297 commit bd95816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/bin/psql/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,8 @@ describeOneTableDetails(const char *schemaname,
if (child_relkind == RELKIND_PARTITIONED_TABLE ||
child_relkind == RELKIND_PARTITIONED_INDEX)
appendPQExpBufferStr(&buf, ", PARTITIONED");
else if (child_relkind == RELKIND_FOREIGN_TABLE)
appendPQExpBufferStr(&buf, ", FOREIGN");
if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
appendPQExpBufferStr(&buf, " (DETACH PENDING)");
if (i < tuples - 1)
Expand Down
36 changes: 18 additions & 18 deletions src/test/regress/expected/foreign_data.out
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ CREATE FOREIGN TABLE ft2 () INHERITS (fd_pt1)
c1 | integer | | not null | | plain | |
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand Down Expand Up @@ -1449,7 +1449,7 @@ ALTER FOREIGN TABLE ft2 INHERIT fd_pt1;
c1 | integer | | not null | | plain | |
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand Down Expand Up @@ -1483,7 +1483,7 @@ Server: s0
FDW options: (delimiter ',', quote '"', "be quoted" 'value')
Inherits: fd_pt1
Child tables: ct3,
ft3
ft3, FOREIGN

\d+ ct3
Table "public.ct3"
Expand Down Expand Up @@ -1522,7 +1522,7 @@ ALTER TABLE fd_pt1 ADD COLUMN c8 integer;
c6 | integer | | | | plain | |
c7 | integer | | not null | | plain | |
c8 | integer | | | | plain | |
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand All @@ -1540,7 +1540,7 @@ Server: s0
FDW options: (delimiter ',', quote '"', "be quoted" 'value')
Inherits: fd_pt1
Child tables: ct3,
ft3
ft3, FOREIGN

\d+ ct3
Table "public.ct3"
Expand Down Expand Up @@ -1596,7 +1596,7 @@ ALTER TABLE fd_pt1 ALTER COLUMN c8 SET STORAGE EXTERNAL;
c6 | integer | | not null | | plain | |
c7 | integer | | | | plain | |
c8 | text | | | | external | |
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand All @@ -1614,7 +1614,7 @@ Server: s0
FDW options: (delimiter ',', quote '"', "be quoted" 'value')
Inherits: fd_pt1
Child tables: ct3,
ft3
ft3, FOREIGN

-- drop attributes recursively
ALTER TABLE fd_pt1 DROP COLUMN c4;
Expand All @@ -1629,7 +1629,7 @@ ALTER TABLE fd_pt1 DROP COLUMN c8;
c1 | integer | | not null | | plain | 10000 |
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand All @@ -1642,7 +1642,7 @@ Server: s0
FDW options: (delimiter ',', quote '"', "be quoted" 'value')
Inherits: fd_pt1
Child tables: ct3,
ft3
ft3, FOREIGN

-- add constraints recursively
ALTER TABLE fd_pt1 ADD CONSTRAINT fd_pt1chk1 CHECK (c1 > 0) NO INHERIT;
Expand All @@ -1669,7 +1669,7 @@ SELECT relname, conname, contype, conislocal, coninhcount, connoinherit
Check constraints:
"fd_pt1chk1" CHECK (c1 > 0) NO INHERIT
"fd_pt1chk2" CHECK (c2 <> ''::text)
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand All @@ -1684,7 +1684,7 @@ Server: s0
FDW options: (delimiter ',', quote '"', "be quoted" 'value')
Inherits: fd_pt1
Child tables: ct3,
ft3
ft3, FOREIGN

DROP FOREIGN TABLE ft2; -- ERROR
ERROR: cannot drop foreign table ft2 because other objects depend on it
Expand Down Expand Up @@ -1716,7 +1716,7 @@ ALTER FOREIGN TABLE ft2 INHERIT fd_pt1;
Check constraints:
"fd_pt1chk1" CHECK (c1 > 0) NO INHERIT
"fd_pt1chk2" CHECK (c2 <> ''::text)
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand Down Expand Up @@ -1746,7 +1746,7 @@ ALTER TABLE fd_pt1 ADD CONSTRAINT fd_pt1chk3 CHECK (c2 <> '') NOT VALID;
c3 | date | | | | plain | |
Check constraints:
"fd_pt1chk3" CHECK (c2 <> ''::text) NOT VALID
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand All @@ -1773,7 +1773,7 @@ ALTER TABLE fd_pt1 VALIDATE CONSTRAINT fd_pt1chk3;
c3 | date | | | | plain | |
Check constraints:
"fd_pt1chk3" CHECK (c2 <> ''::text)
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand Down Expand Up @@ -1804,7 +1804,7 @@ ALTER TABLE fd_pt1 RENAME CONSTRAINT fd_pt1chk3 TO f2_check;
f3 | date | | | | plain | |
Check constraints:
"f2_check" CHECK (f2 <> ''::text)
Child tables: ft2
Child tables: ft2, FOREIGN

\d+ ft2
Foreign table "public.ft2"
Expand Down Expand Up @@ -1862,7 +1862,7 @@ CREATE FOREIGN TABLE fd_pt2_1 PARTITION OF fd_pt2 FOR VALUES IN (1)
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Partition key: LIST (c1)
Partitions: fd_pt2_1 FOR VALUES IN (1)
Partitions: fd_pt2_1 FOR VALUES IN (1), FOREIGN

\d+ fd_pt2_1
Foreign table "public.fd_pt2_1"
Expand Down Expand Up @@ -1934,7 +1934,7 @@ ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Partition key: LIST (c1)
Partitions: fd_pt2_1 FOR VALUES IN (1)
Partitions: fd_pt2_1 FOR VALUES IN (1), FOREIGN

\d+ fd_pt2_1
Foreign table "public.fd_pt2_1"
Expand Down Expand Up @@ -1962,7 +1962,7 @@ ALTER TABLE fd_pt2_1 ADD CONSTRAINT p21chk CHECK (c2 <> '');
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Partition key: LIST (c1)
Partitions: fd_pt2_1 FOR VALUES IN (1)
Partitions: fd_pt2_1 FOR VALUES IN (1), FOREIGN

\d+ fd_pt2_1
Foreign table "public.fd_pt2_1"
Expand Down

0 comments on commit bd95816

Please sign in to comment.