Skip to content

Commit e0a1f0f

Browse files
author
Nikita Glukhov
committed
psql: Add column compression info to \d command
1 parent 3873c8f commit e0a1f0f

File tree

11 files changed

+309
-285
lines changed

11 files changed

+309
-285
lines changed

contrib/test_decoding/expected/ddl.out

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ CREATE TABLE replication_metadata (
416416
WITH (user_catalog_table = true)
417417
;
418418
\d+ replication_metadata
419-
Table "public.replication_metadata"
420-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
421-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
422-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
423-
relation | name | | not null | | plain | |
424-
options | text[] | | | | extended | |
419+
Table "public.replication_metadata"
420+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
421+
----------+---------+-----------+----------+--------------------------------------------------+----------+-------------+--------------+-------------
422+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | | |
423+
relation | name | | not null | | plain | | |
424+
options | text[] | | | | extended | | |
425425
Indexes:
426426
"replication_metadata_pkey" PRIMARY KEY, btree (id)
427427
Options: user_catalog_table=true
@@ -430,25 +430,25 @@ INSERT INTO replication_metadata(relation, options)
430430
VALUES ('foo', ARRAY['a', 'b']);
431431
ALTER TABLE replication_metadata RESET (user_catalog_table);
432432
\d+ replication_metadata
433-
Table "public.replication_metadata"
434-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
435-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
436-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
437-
relation | name | | not null | | plain | |
438-
options | text[] | | | | extended | |
433+
Table "public.replication_metadata"
434+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
435+
----------+---------+-----------+----------+--------------------------------------------------+----------+-------------+--------------+-------------
436+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | | |
437+
relation | name | | not null | | plain | | |
438+
options | text[] | | | | extended | | |
439439
Indexes:
440440
"replication_metadata_pkey" PRIMARY KEY, btree (id)
441441

442442
INSERT INTO replication_metadata(relation, options)
443443
VALUES ('bar', ARRAY['a', 'b']);
444444
ALTER TABLE replication_metadata SET (user_catalog_table = true);
445445
\d+ replication_metadata
446-
Table "public.replication_metadata"
447-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
448-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
449-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
450-
relation | name | | not null | | plain | |
451-
options | text[] | | | | extended | |
446+
Table "public.replication_metadata"
447+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
448+
----------+---------+-----------+----------+--------------------------------------------------+----------+-------------+--------------+-------------
449+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | | |
450+
relation | name | | not null | | plain | | |
451+
options | text[] | | | | extended | | |
452452
Indexes:
453453
"replication_metadata_pkey" PRIMARY KEY, btree (id)
454454
Options: user_catalog_table=true
@@ -461,13 +461,13 @@ ALTER TABLE replication_metadata ALTER COLUMN rewritemeornot TYPE text;
461461
ERROR: cannot rewrite table "replication_metadata" used as a catalog table
462462
ALTER TABLE replication_metadata SET (user_catalog_table = false);
463463
\d+ replication_metadata
464-
Table "public.replication_metadata"
465-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
466-
----------------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
467-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
468-
relation | name | | not null | | plain | |
469-
options | text[] | | | | extended | |
470-
rewritemeornot | integer | | | | plain | |
464+
Table "public.replication_metadata"
465+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
466+
----------------+---------+-----------+----------+--------------------------------------------------+----------+-------------+--------------+-------------
467+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | | |
468+
relation | name | | not null | | plain | | |
469+
options | text[] | | | | extended | | |
470+
rewritemeornot | integer | | | | plain | | |
471471
Indexes:
472472
"replication_metadata_pkey" PRIMARY KEY, btree (id)
473473
Options: user_catalog_table=false

src/bin/psql/describe.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,21 @@ describeOneTableDetails(const char *schemaname,
16101610
if (verbose)
16111611
{
16121612
appendPQExpBufferStr(&buf, ",\n a.attstorage");
1613+
1614+
if (pset.sversion >= 100000)
1615+
appendPQExpBufferStr(&buf, ",\n CASE WHEN attcompression = 0 THEN NULL ELSE "
1616+
" (SELECT c.cmname || "
1617+
" (CASE WHEN attcmoptions IS NULL "
1618+
" THEN '' "
1619+
" ELSE '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value)"
1620+
" FROM pg_options_to_table(attcmoptions)), ', ') || ')'"
1621+
" END) "
1622+
" FROM pg_catalog.pg_compression c "
1623+
" WHERE c.oid = a.attcompression) "
1624+
" END AS attcmname");
1625+
else
1626+
appendPQExpBufferStr(&buf, "\n NULL AS attcmname");
1627+
16131628
appendPQExpBufferStr(&buf, ",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
16141629

16151630
/*
@@ -1731,6 +1746,10 @@ describeOneTableDetails(const char *schemaname,
17311746
if (verbose)
17321747
{
17331748
headers[cols++] = gettext_noop("Storage");
1749+
1750+
if (tableinfo.relkind == RELKIND_RELATION)
1751+
headers[cols++] = gettext_noop("Compression");
1752+
17341753
if (tableinfo.relkind == RELKIND_RELATION ||
17351754
tableinfo.relkind == RELKIND_MATVIEW ||
17361755
tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
@@ -1829,13 +1848,18 @@ describeOneTableDetails(const char *schemaname,
18291848
"???")))),
18301849
false, false);
18311850

1851+
/* Column compression. */
1852+
if (tableinfo.relkind == RELKIND_RELATION)
1853+
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1854+
false, false);
1855+
18321856
/* Statistics target, if the relkind supports this feature */
18331857
if (tableinfo.relkind == RELKIND_RELATION ||
18341858
tableinfo.relkind == RELKIND_MATVIEW ||
18351859
tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
18361860
tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
18371861
{
1838-
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
1862+
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 2),
18391863
false, false);
18401864
}
18411865

@@ -1846,7 +1870,7 @@ describeOneTableDetails(const char *schemaname,
18461870
tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
18471871
tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
18481872
tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1849-
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 2),
1873+
printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 3),
18501874
false, false);
18511875
}
18521876
}

src/test/regress/expected/copy2.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ begin
438438
end $$ language plpgsql immutable;
439439
alter table check_con_tbl add check (check_con_function(check_con_tbl.*));
440440
\d+ check_con_tbl
441-
Table "public.check_con_tbl"
442-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
443-
--------+---------+-----------+----------+---------+---------+--------------+-------------
444-
f1 | integer | | | | plain | |
441+
Table "public.check_con_tbl"
442+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
443+
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
444+
f1 | integer | | | | plain | | |
445445
Check constraints:
446446
"check_con_tbl_check" CHECK (check_con_function(check_con_tbl.*))
447447

src/test/regress/expected/create_table.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ CREATE TABLE oids_parted (
534534
) PARTITION BY RANGE (a) WITH OIDS;
535535
CREATE TABLE part_forced_oids PARTITION OF oids_parted FOR VALUES FROM (1) TO (10) WITHOUT OIDS;
536536
\d+ part_forced_oids
537-
Table "public.part_forced_oids"
538-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
539-
--------+---------+-----------+----------+---------+---------+--------------+-------------
540-
a | integer | | not null | | plain | |
537+
Table "public.part_forced_oids"
538+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
539+
--------+---------+-----------+----------+---------+---------+-------------+--------------+-------------
540+
a | integer | | not null | | plain | | |
541541
Partition of: oids_parted FOR VALUES FROM (1) TO (10)
542542
Has OIDs: yes
543543

src/test/regress/expected/create_table_like.out

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -156,32 +156,32 @@ CREATE TABLE ctlt4 (a text, c text);
156156
ALTER TABLE ctlt4 ALTER COLUMN c SET STORAGE EXTERNAL;
157157
CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, LIKE ctlt2 INCLUDING STORAGE);
158158
\d+ ctlt12_storage
159-
Table "public.ctlt12_storage"
160-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
161-
--------+------+-----------+----------+---------+----------+--------------+-------------
162-
a | text | | not null | | main | |
163-
b | text | | | | extended | |
164-
c | text | | | | external | |
159+
Table "public.ctlt12_storage"
160+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
161+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
162+
a | text | | not null | | main | | |
163+
b | text | | | | extended | | |
164+
c | text | | | | external | | |
165165

166166
CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 INCLUDING COMMENTS);
167167
\d+ ctlt12_comments
168-
Table "public.ctlt12_comments"
169-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
170-
--------+------+-----------+----------+---------+----------+--------------+-------------
171-
a | text | | not null | | extended | | A
172-
b | text | | | | extended | | B
173-
c | text | | | | extended | | C
168+
Table "public.ctlt12_comments"
169+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
170+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
171+
a | text | | not null | | extended | | | A
172+
b | text | | | | extended | | | B
173+
c | text | | | | extended | | | C
174174

175175
CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
176176
NOTICE: merging column "a" with inherited definition
177177
NOTICE: merging column "b" with inherited definition
178178
NOTICE: merging constraint "ctlt1_a_check" with inherited definition
179179
\d+ ctlt1_inh
180-
Table "public.ctlt1_inh"
181-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
182-
--------+------+-----------+----------+---------+----------+--------------+-------------
183-
a | text | | not null | | main | | A
184-
b | text | | | | extended | | B
180+
Table "public.ctlt1_inh"
181+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
182+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
183+
a | text | | not null | | main | | | A
184+
b | text | | | | extended | | | B
185185
Check constraints:
186186
"ctlt1_a_check" CHECK (length(a) > 2)
187187
Inherits: ctlt1
@@ -195,12 +195,12 @@ SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_con
195195
CREATE TABLE ctlt13_inh () INHERITS (ctlt1, ctlt3);
196196
NOTICE: merging multiple inherited definitions of column "a"
197197
\d+ ctlt13_inh
198-
Table "public.ctlt13_inh"
199-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
200-
--------+------+-----------+----------+---------+----------+--------------+-------------
201-
a | text | | not null | | main | |
202-
b | text | | | | extended | |
203-
c | text | | | | external | |
198+
Table "public.ctlt13_inh"
199+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
200+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
201+
a | text | | not null | | main | | |
202+
b | text | | | | extended | | |
203+
c | text | | | | external | | |
204204
Check constraints:
205205
"ctlt1_a_check" CHECK (length(a) > 2)
206206
"ctlt3_a_check" CHECK (length(a) < 5)
@@ -210,12 +210,12 @@ Inherits: ctlt1,
210210
CREATE TABLE ctlt13_like (LIKE ctlt3 INCLUDING CONSTRAINTS INCLUDING COMMENTS INCLUDING STORAGE) INHERITS (ctlt1);
211211
NOTICE: merging column "a" with inherited definition
212212
\d+ ctlt13_like
213-
Table "public.ctlt13_like"
214-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
215-
--------+------+-----------+----------+---------+----------+--------------+-------------
216-
a | text | | not null | | main | | A3
217-
b | text | | | | extended | |
218-
c | text | | | | external | | C
213+
Table "public.ctlt13_like"
214+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
215+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
216+
a | text | | not null | | main | | | A3
217+
b | text | | | | extended | | |
218+
c | text | | | | external | | | C
219219
Check constraints:
220220
"ctlt1_a_check" CHECK (length(a) > 2)
221221
"ctlt3_a_check" CHECK (length(a) < 5)
@@ -229,11 +229,11 @@ SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_con
229229

230230
CREATE TABLE ctlt_all (LIKE ctlt1 INCLUDING ALL);
231231
\d+ ctlt_all
232-
Table "public.ctlt_all"
233-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
234-
--------+------+-----------+----------+---------+----------+--------------+-------------
235-
a | text | | not null | | main | | A
236-
b | text | | | | extended | | B
232+
Table "public.ctlt_all"
233+
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
234+
--------+------+-----------+----------+---------+----------+-------------+--------------+-------------
235+
a | text | | not null | | main | | | A
236+
b | text | | | | extended | | | B
237237
Indexes:
238238
"ctlt_all_pkey" PRIMARY KEY, btree (a)
239239
"ctlt_all_b_idx" btree (b)

0 commit comments

Comments
 (0)