Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d56e0fd

Browse files
committed
psql: Describe partitioned tables/indexes as such
In \d and \z, instead of conflating partitioned tables and indexes with plain ones, set the "type" column and table title differently to make the distinction obvious. A simple ease-of-use improvement. Author: Pavel Stehule, Michaël Paquier, Álvaro Herrera Reviewed-by: Amit Langote Discussion: https://postgr.es/m/CAFj8pRDMWPgijpt_vPj1t702PgLG4Ls2NCf+rEcb+qGPpossmg@mail.gmail.com
1 parent df303af commit d56e0fd

File tree

7 files changed

+39
-32
lines changed

7 files changed

+39
-32
lines changed

src/bin/psql/describe.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ permissionsList(const char *pattern)
955955
gettext_noop("materialized view"),
956956
gettext_noop("sequence"),
957957
gettext_noop("foreign table"),
958-
gettext_noop("table"), /* partitioned table */
958+
gettext_noop("partitioned table"),
959959
gettext_noop("Type"));
960960

961961
printACLColumn(&buf, "c.relacl");
@@ -1896,14 +1896,21 @@ describeOneTableDetails(const char *schemaname,
18961896
schemaname, relationname);
18971897
break;
18981898
case RELKIND_INDEX:
1899-
case RELKIND_PARTITIONED_INDEX:
19001899
if (tableinfo.relpersistence == 'u')
19011900
printfPQExpBuffer(&title, _("Unlogged index \"%s.%s\""),
19021901
schemaname, relationname);
19031902
else
19041903
printfPQExpBuffer(&title, _("Index \"%s.%s\""),
19051904
schemaname, relationname);
19061905
break;
1906+
case RELKIND_PARTITIONED_INDEX:
1907+
if (tableinfo.relpersistence == 'u')
1908+
printfPQExpBuffer(&title, _("Unlogged partitioned index \"%s.%s\""),
1909+
schemaname, relationname);
1910+
else
1911+
printfPQExpBuffer(&title, _("Partitioned index \"%s.%s\""),
1912+
schemaname, relationname);
1913+
break;
19071914
case 's':
19081915
/* not used as of 8.2, but keep it for backwards compatibility */
19091916
printfPQExpBuffer(&title, _("Special relation \"%s.%s\""),
@@ -1923,10 +1930,10 @@ describeOneTableDetails(const char *schemaname,
19231930
break;
19241931
case RELKIND_PARTITIONED_TABLE:
19251932
if (tableinfo.relpersistence == 'u')
1926-
printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
1933+
printfPQExpBuffer(&title, _("Unlogged partitioned table \"%s.%s\""),
19271934
schemaname, relationname);
19281935
else
1929-
printfPQExpBuffer(&title, _("Table \"%s.%s\""),
1936+
printfPQExpBuffer(&title, _("Partitioned table \"%s.%s\""),
19301937
schemaname, relationname);
19311938
break;
19321939
default:
@@ -3524,8 +3531,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
35243531
gettext_noop("sequence"),
35253532
gettext_noop("special"),
35263533
gettext_noop("foreign table"),
3527-
gettext_noop("table"), /* partitioned table */
3528-
gettext_noop("index"), /* partitioned index */
3534+
gettext_noop("partitioned table"),
3535+
gettext_noop("partitioned index"),
35293536
gettext_noop("Type"),
35303537
gettext_noop("Owner"));
35313538

src/test/regress/expected/create_table.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ CREATE TABLE fail () INHERITS (partitioned2);
403403
ERROR: cannot inherit from partitioned table "partitioned2"
404404
-- Partition key in describe output
405405
\d partitioned
406-
Table "public.partitioned"
406+
Partitioned table "public.partitioned"
407407
Column | Type | Collation | Nullable | Default
408408
--------+---------+-----------+----------+---------
409409
a | integer | | |
@@ -414,7 +414,7 @@ Partition key: RANGE (a oid_ops, plusone(b), c, d COLLATE "C")
414414
Number of partitions: 0
415415

416416
\d+ partitioned2
417-
Table "public.partitioned2"
417+
Partitioned table "public.partitioned2"
418418
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
419419
--------+---------+-----------+----------+---------+----------+--------------+-------------
420420
a | integer | | | | plain | |
@@ -769,7 +769,7 @@ Check constraints:
769769

770770
-- Both partition bound and partition key in describe output
771771
\d+ part_c
772-
Table "public.part_c"
772+
Partitioned table "public.part_c"
773773
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
774774
--------+---------+-----------+----------+---------+----------+--------------+-------------
775775
a | text | | | | extended | |
@@ -798,7 +798,7 @@ Check constraints:
798798
-- output could vary depending on the order in which partition oids are
799799
-- returned.
800800
\d parted
801-
Table "public.parted"
801+
Partitioned table "public.parted"
802802
Column | Type | Collation | Nullable | Default
803803
--------+---------+-----------+----------+---------
804804
a | text | | |
@@ -809,7 +809,7 @@ Check constraints:
809809
Number of partitions: 3 (Use \d+ to list them.)
810810

811811
\d hash_parted
812-
Table "public.hash_parted"
812+
Partitioned table "public.hash_parted"
813813
Column | Type | Collation | Nullable | Default
814814
--------+---------+-----------+----------+---------
815815
a | integer | | |
@@ -891,7 +891,7 @@ SELECT obj_description('parted_col_comment'::regclass);
891891
(1 row)
892892

893893
\d+ parted_col_comment
894-
Table "public.parted_col_comment"
894+
Partitioned table "public.parted_col_comment"
895895
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
896896
--------+---------+-----------+----------+---------+----------+--------------+---------------
897897
a | integer | | | | plain | | Partition key
@@ -917,7 +917,7 @@ create table boolspart (a bool) partition by list (a);
917917
create table boolspart_t partition of boolspart for values in (true);
918918
create table boolspart_f partition of boolspart for values in (false);
919919
\d+ boolspart
920-
Table "public.boolspart"
920+
Partitioned table "public.boolspart"
921921
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
922922
--------+---------+-----------+----------+---------+---------+--------------+-------------
923923
a | boolean | | | | plain | |

src/test/regress/expected/foreign_data.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ CREATE TABLE fd_pt2 (
18531853
CREATE FOREIGN TABLE fd_pt2_1 PARTITION OF fd_pt2 FOR VALUES IN (1)
18541854
SERVER s0 OPTIONS (delimiter ',', quote '"', "be quoted" 'value');
18551855
\d+ fd_pt2
1856-
Table "public.fd_pt2"
1856+
Partitioned table "public.fd_pt2"
18571857
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
18581858
--------+---------+-----------+----------+---------+----------+--------------+-------------
18591859
c1 | integer | | not null | | plain | |
@@ -1898,7 +1898,7 @@ ERROR: table "fd_pt2_1" contains column "c4" not found in parent "fd_pt2"
18981898
DETAIL: The new partition may contain only the columns present in parent.
18991899
DROP FOREIGN TABLE fd_pt2_1;
19001900
\d+ fd_pt2
1901-
Table "public.fd_pt2"
1901+
Partitioned table "public.fd_pt2"
19021902
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
19031903
--------+---------+-----------+----------+---------+----------+--------------+-------------
19041904
c1 | integer | | not null | | plain | |
@@ -1925,7 +1925,7 @@ FDW options: (delimiter ',', quote '"', "be quoted" 'value')
19251925
-- no attach partition validation occurs for foreign tables
19261926
ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
19271927
\d+ fd_pt2
1928-
Table "public.fd_pt2"
1928+
Partitioned table "public.fd_pt2"
19291929
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
19301930
--------+---------+-----------+----------+---------+----------+--------------+-------------
19311931
c1 | integer | | not null | | plain | |
@@ -1953,7 +1953,7 @@ ERROR: cannot add column to a partition
19531953
ALTER TABLE fd_pt2_1 ALTER c3 SET NOT NULL;
19541954
ALTER TABLE fd_pt2_1 ADD CONSTRAINT p21chk CHECK (c2 <> '');
19551955
\d+ fd_pt2
1956-
Table "public.fd_pt2"
1956+
Partitioned table "public.fd_pt2"
19571957
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
19581958
--------+---------+-----------+----------+---------+----------+--------------+-------------
19591959
c1 | integer | | not null | | plain | |
@@ -1983,7 +1983,7 @@ ERROR: column "c1" is marked NOT NULL in parent table
19831983
ALTER TABLE fd_pt2 DETACH PARTITION fd_pt2_1;
19841984
ALTER TABLE fd_pt2 ALTER c2 SET NOT NULL;
19851985
\d+ fd_pt2
1986-
Table "public.fd_pt2"
1986+
Partitioned table "public.fd_pt2"
19871987
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
19881988
--------+---------+-----------+----------+---------+----------+--------------+-------------
19891989
c1 | integer | | not null | | plain | |
@@ -2011,7 +2011,7 @@ ALTER TABLE fd_pt2 ATTACH PARTITION fd_pt2_1 FOR VALUES IN (1);
20112011
ALTER TABLE fd_pt2 DETACH PARTITION fd_pt2_1;
20122012
ALTER TABLE fd_pt2 ADD CONSTRAINT fd_pt2chk1 CHECK (c1 > 0);
20132013
\d+ fd_pt2
2014-
Table "public.fd_pt2"
2014+
Partitioned table "public.fd_pt2"
20152015
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
20162016
--------+---------+-----------+----------+---------+----------+--------------+-------------
20172017
c1 | integer | | not null | | plain | |

src/test/regress/expected/foreign_key.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ ALTER TABLE fk_partitioned_fk DETACH PARTITION fk_partitioned_fk_4;
16921692
ALTER TABLE fk_partitioned_fk ATTACH PARTITION fk_partitioned_fk_4 FOR VALUES IN (3500,3502);
16931693
-- should only have one constraint
16941694
\d fk_partitioned_fk_4
1695-
Table "public.fk_partitioned_fk_4"
1695+
Partitioned table "public.fk_partitioned_fk_4"
16961696
Column | Type | Collation | Nullable | Default
16971697
--------+---------+-----------+----------+---------
16981698
a | integer | | |
@@ -1737,7 +1737,7 @@ ALTER TABLE fk_partitioned_fk ATTACH PARTITION fk_partitioned_fk_5 FOR VALUES IN
17371737
-- this one has two constraints, similar but not quite the one in the parent,
17381738
-- so it gets a new one
17391739
\d fk_partitioned_fk_5
1740-
Table "public.fk_partitioned_fk_5"
1740+
Partitioned table "public.fk_partitioned_fk_5"
17411741
Column | Type | Collation | Nullable | Default
17421742
--------+---------+-----------+----------+---------
17431743
a | integer | | |

src/test/regress/expected/indexing.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Indexes:
260260
"idxpart1_a_idx" btree (a)
261261

262262
\d idxpart2
263-
Table "public.idxpart2"
263+
Partitioned table "public.idxpart2"
264264
Column | Type | Collation | Nullable | Default
265265
--------+---------+-----------+----------+---------
266266
a | integer | | |
@@ -305,7 +305,7 @@ where indexrelid::regclass::text like 'idxpart%'
305305
-- attaching idxpart22 is not enough to set idxpart22_a_idx valid ...
306306
alter index idxpart2_a_idx attach partition idxpart22_a_idx;
307307
\d idxpart2
308-
Table "public.idxpart2"
308+
Partitioned table "public.idxpart2"
309309
Column | Type | Collation | Nullable | Default
310310
--------+---------+-----------+----------+---------
311311
a | integer | | |
@@ -319,7 +319,7 @@ Number of partitions: 2 (Use \d+ to list them.)
319319
create index on idxpart21 (a);
320320
alter index idxpart2_a_idx attach partition idxpart21_a_idx;
321321
\d idxpart2
322-
Table "public.idxpart2"
322+
Partitioned table "public.idxpart2"
323323
Column | Type | Collation | Nullable | Default
324324
--------+---------+-----------+----------+---------
325325
a | integer | | |
@@ -728,7 +728,7 @@ create table idxpart (col_keep int) partition by range (col_keep);
728728
create index on idxpart (col_keep);
729729
alter table idxpart attach partition idxpart1 for values from (0) to (1000);
730730
\d idxpart
731-
Table "public.idxpart"
731+
Partitioned table "public.idxpart"
732732
Column | Type | Collation | Nullable | Default
733733
----------+---------+-----------+----------+---------
734734
col_keep | integer | | |
@@ -771,7 +771,7 @@ create index on idxpart1 (col_keep);
771771
create index on idxpart (col_keep);
772772
alter table idxpart attach partition idxpart1 for values from (0) to (1000);
773773
\d idxpart
774-
Table "public.idxpart"
774+
Partitioned table "public.idxpart"
775775
Column | Type | Collation | Nullable | Default
776776
----------+---------+-----------+----------+---------
777777
col_keep | integer | | |
@@ -810,7 +810,7 @@ drop table idxpart;
810810
-- Verify that it works to add primary key / unique to partitioned tables
811811
create table idxpart (a int primary key, b int) partition by range (a);
812812
\d idxpart
813-
Table "public.idxpart"
813+
Partitioned table "public.idxpart"
814814
Column | Type | Collation | Nullable | Default
815815
--------+---------+-----------+----------+---------
816816
a | integer | | not null |
@@ -872,7 +872,7 @@ ERROR: insufficient columns in PRIMARY KEY constraint definition
872872
DETAIL: PRIMARY KEY constraint on table "idxpart" lacks column "b" which is part of the partition key.
873873
alter table idxpart add primary key (a, b); -- this works
874874
\d idxpart
875-
Table "public.idxpart"
875+
Partitioned table "public.idxpart"
876876
Column | Type | Collation | Nullable | Default
877877
--------+---------+-----------+----------+---------
878878
a | integer | | not null |
@@ -903,7 +903,7 @@ ERROR: insufficient columns in UNIQUE constraint definition
903903
DETAIL: UNIQUE constraint on table "idxpart" lacks column "b" which is part of the partition key.
904904
alter table idxpart add unique (b, a); -- this works
905905
\d idxpart
906-
Table "public.idxpart"
906+
Partitioned table "public.idxpart"
907907
Column | Type | Collation | Nullable | Default
908908
--------+---------+-----------+----------+---------
909909
a | integer | | |

src/test/regress/expected/insert.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ from hash_parted order by part;
448448
-- test \d+ output on a table which has both partitioned and unpartitioned
449449
-- partitions
450450
\d+ list_parted
451-
Table "public.list_parted"
451+
Partitioned table "public.list_parted"
452452
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
453453
--------+---------+-----------+----------+---------+----------+--------------+-------------
454454
a | text | | | | extended | |
@@ -799,7 +799,7 @@ create table mcrparted6_common_ge_10 partition of mcrparted for values from ('co
799799
create table mcrparted7_gt_common_lt_d partition of mcrparted for values from ('common', maxvalue) to ('d', minvalue);
800800
create table mcrparted8_ge_d partition of mcrparted for values from ('d', minvalue) to (maxvalue, maxvalue);
801801
\d+ mcrparted
802-
Table "public.mcrparted"
802+
Partitioned table "public.mcrparted"
803803
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
804804
--------+---------+-----------+----------+---------+----------+--------------+-------------
805805
a | text | | | | extended | |

src/test/regress/expected/rowsecurity.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ CREATE POLICY pp1 ON part_document AS PERMISSIVE
938938
CREATE POLICY pp1r ON part_document AS RESTRICTIVE TO regress_rls_dave
939939
USING (cid < 55);
940940
\d+ part_document
941-
Table "regress_rls_schema.part_document"
941+
Partitioned table "regress_rls_schema.part_document"
942942
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
943943
---------+---------+-----------+----------+---------+----------+--------------+-------------
944944
did | integer | | | | plain | |

0 commit comments

Comments
 (0)