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

Commit 4168c00

Browse files
committed
psql: conditionally display oids and replication identity
In psql \d+, display oids only when they exist, and display replication identity only when it is non-default. Also document the defaults for replication identity for system and non-system tables. Update regression output.
1 parent c92c3d5 commit 4168c00

File tree

9 files changed

+21
-44
lines changed

9 files changed

+21
-44
lines changed

doc/src/sgml/ref/alter_table.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,14 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
608608
<para>
609609
This form changes the information which is written to the write-ahead log
610610
to identify rows which are updated or deleted. This option has no effect
611-
except when logical replication is in use. <literal>DEFAULT</> records the
611+
except when logical replication is in use. <literal>DEFAULT</>
612+
(the default for non-system tables) records the
612613
old values of the columns of the primary key, if any. <literal>USING INDEX</>
613614
records the old values of the columns covered by the named index, which
614615
must be unique, not partial, not deferrable, and include only columns marked
615616
<literal>NOT NULL</>. <literal>FULL</> records the old values of all columns
616617
in the row. <literal>NOTHING</> records no information about the old row.
618+
(This is the default for system tables.)
617619
In all cases, no old values are logged unless at least one of the columns
618620
that would be logged differs between the old and new versions of the row.
619621
</para>

doc/src/sgml/ref/psql-ref.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,9 @@ testdb=&gt;
951951
The command form <literal>\d+</literal> is identical, except that
952952
more information is displayed: any comments associated with the
953953
columns of the table are shown, as is the presence of OIDs in the
954-
table, the view definition if the relation is a view.
954+
table, the view definition if the relation is a view, a non-default
955+
<link linkend="SQL-CREATETABLE-REPLICA-IDENTITY">replica
956+
identity</link> setting.
955957
</para>
956958

957959
<para>

src/bin/psql/describe.c

+6-11
Original file line numberDiff line numberDiff line change
@@ -2345,13 +2345,14 @@ describeOneTableDetails(const char *schemaname,
23452345
printTableAddFooter(&cont, buf.data);
23462346
}
23472347

2348-
if ((tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
2348+
if (verbose && (tableinfo.relkind == 'r' || tableinfo.relkind == 'm') &&
23492349
/*
23502350
* No need to display default values; we already display a
23512351
* REPLICA IDENTITY marker on indexes.
23522352
*/
2353-
tableinfo.relreplident != 'd' && tableinfo.relreplident != 'i' &&
2354-
strcmp(schemaname, "pg_catalog") != 0)
2353+
tableinfo.relreplident != 'i' &&
2354+
((strcmp(schemaname, "pg_catalog") != 0 && tableinfo.relreplident != 'd') ||
2355+
(strcmp(schemaname, "pg_catalog") == 0 && tableinfo.relreplident != 'n')))
23552356
{
23562357
const char *s = _("Replica Identity");
23572358

@@ -2365,14 +2366,8 @@ describeOneTableDetails(const char *schemaname,
23652366
}
23662367

23672368
/* OIDs, if verbose and not a materialized view */
2368-
if (verbose && tableinfo.relkind != 'm')
2369-
{
2370-
const char *s = _("Has OIDs");
2371-
2372-
printfPQExpBuffer(&buf, "%s: %s", s,
2373-
(tableinfo.hasoids ? _("yes") : _("no")));
2374-
printTableAddFooter(&cont, buf.data);
2375-
}
2369+
if (verbose && tableinfo.relkind != 'm' && tableinfo.hasoids)
2370+
printTableAddFooter(&cont, _("Has OIDs: yes"));
23762371

23772372
/* Tablespace info */
23782373
add_tablespace_footer(&cont, tableinfo.relkind, tableinfo.tablespace,

src/test/regress/expected/create_table_like.out

-6
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ CREATE TABLE ctlt12_storage (LIKE ctlt1 INCLUDING STORAGE, LIKE ctlt2 INCLUDING
115115
a | text | not null | main | |
116116
b | text | | extended | |
117117
c | text | | external | |
118-
Has OIDs: no
119118

120119
CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 INCLUDING COMMENTS);
121120
\d+ ctlt12_comments
@@ -125,7 +124,6 @@ CREATE TABLE ctlt12_comments (LIKE ctlt1 INCLUDING COMMENTS, LIKE ctlt2 INCLUDIN
125124
a | text | not null | extended | | A
126125
b | text | | extended | | B
127126
c | text | | extended | | C
128-
Has OIDs: no
129127

130128
CREATE TABLE ctlt1_inh (LIKE ctlt1 INCLUDING CONSTRAINTS INCLUDING COMMENTS) INHERITS (ctlt1);
131129
NOTICE: merging column "a" with inherited definition
@@ -140,7 +138,6 @@ NOTICE: merging constraint "ctlt1_a_check" with inherited definition
140138
Check constraints:
141139
"ctlt1_a_check" CHECK (length(a) > 2)
142140
Inherits: ctlt1
143-
Has OIDs: no
144141

145142
SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt1_inh'::regclass;
146143
description
@@ -162,7 +159,6 @@ Check constraints:
162159
"ctlt3_a_check" CHECK (length(a) < 5)
163160
Inherits: ctlt1,
164161
ctlt3
165-
Has OIDs: no
166162

167163
CREATE TABLE ctlt13_like (LIKE ctlt3 INCLUDING CONSTRAINTS INCLUDING COMMENTS INCLUDING STORAGE) INHERITS (ctlt1);
168164
NOTICE: merging column "a" with inherited definition
@@ -177,7 +173,6 @@ Check constraints:
177173
"ctlt1_a_check" CHECK (length(a) > 2)
178174
"ctlt3_a_check" CHECK (length(a) < 5)
179175
Inherits: ctlt1
180-
Has OIDs: no
181176

182177
SELECT description FROM pg_description, pg_constraint c WHERE classoid = 'pg_constraint'::regclass AND objoid = c.oid AND c.conrelid = 'ctlt13_like'::regclass;
183178
description
@@ -198,7 +193,6 @@ Indexes:
198193
"ctlt_all_expr_idx" btree ((a || b))
199194
Check constraints:
200195
"ctlt1_a_check" CHECK (length(a) > 2)
201-
Has OIDs: no
202196

203197
SELECT c.relname, objsubid, description FROM pg_description, pg_index i, pg_class c WHERE classoid = 'pg_class'::regclass AND objoid = i.indexrelid AND c.oid = i.indexrelid AND i.indrelid = 'ctlt_all'::regclass ORDER BY c.relname, objsubid;
204198
relname | objsubid | description

src/test/regress/expected/foreign_data.out

-2
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ COMMENT ON COLUMN ft1.c1 IS 'ft1.c1';
684684
c3 | date | | | plain | |
685685
Server: s0
686686
FDW Options: (delimiter ',', quote '"', "be quoted" 'value')
687-
Has OIDs: no
688687

689688
\det+
690689
List of foreign tables
@@ -743,7 +742,6 @@ ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 SET STATISTICS -1;
743742
c10 | integer | | (p1 'v1') | plain | |
744743
Server: s0
745744
FDW Options: (delimiter ',', quote '"', "be quoted" 'value')
746-
Has OIDs: no
747745

748746
-- can't change the column type if it's used elsewhere
749747
CREATE TABLE use_ft1_column_type (x ft1);

src/test/regress/expected/inherit.out

-13
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,6 @@ ALTER TABLE inhts RENAME d TO dd;
913913
dd | integer | | plain | |
914914
Inherits: inht1,
915915
inhs1
916-
Has OIDs: no
917916

918917
DROP TABLE inhts;
919918
-- Test for renaming in diamond inheritance
@@ -934,7 +933,6 @@ ALTER TABLE inht1 RENAME aa TO aaa;
934933
z | integer | | plain | |
935934
Inherits: inht2,
936935
inht3
937-
Has OIDs: no
938936

939937
CREATE TABLE inhts (d int) INHERITS (inht2, inhs1);
940938
NOTICE: merging multiple inherited definitions of column "b"
@@ -952,7 +950,6 @@ ERROR: cannot rename inherited column "b"
952950
d | integer | | plain | |
953951
Inherits: inht2,
954952
inhs1
955-
Has OIDs: no
956953

957954
WITH RECURSIVE r AS (
958955
SELECT 'inht1'::regclass AS inhrelid
@@ -999,7 +996,6 @@ CREATE TABLE test_constraints_inh () INHERITS (test_constraints);
999996
Indexes:
1000997
"test_constraints_val1_val2_key" UNIQUE CONSTRAINT, btree (val1, val2)
1001998
Child tables: test_constraints_inh
1002-
Has OIDs: no
1003999

10041000
ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key;
10051001
\d+ test_constraints
@@ -1010,7 +1006,6 @@ ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key
10101006
val1 | character varying | | extended | |
10111007
val2 | integer | | plain | |
10121008
Child tables: test_constraints_inh
1013-
Has OIDs: no
10141009

10151010
\d+ test_constraints_inh
10161011
Table "public.test_constraints_inh"
@@ -1020,7 +1015,6 @@ Has OIDs: no
10201015
val1 | character varying | | extended | |
10211016
val2 | integer | | plain | |
10221017
Inherits: test_constraints
1023-
Has OIDs: no
10241018

10251019
DROP TABLE test_constraints_inh;
10261020
DROP TABLE test_constraints;
@@ -1037,7 +1031,6 @@ CREATE TABLE test_ex_constraints_inh () INHERITS (test_ex_constraints);
10371031
Indexes:
10381032
"test_ex_constraints_c_excl" EXCLUDE USING gist (c WITH &&)
10391033
Child tables: test_ex_constraints_inh
1040-
Has OIDs: no
10411034

10421035
ALTER TABLE test_ex_constraints DROP CONSTRAINT test_ex_constraints_c_excl;
10431036
\d+ test_ex_constraints
@@ -1046,15 +1039,13 @@ ALTER TABLE test_ex_constraints DROP CONSTRAINT test_ex_constraints_c_excl;
10461039
--------+--------+-----------+---------+--------------+-------------
10471040
c | circle | | plain | |
10481041
Child tables: test_ex_constraints_inh
1049-
Has OIDs: no
10501042

10511043
\d+ test_ex_constraints_inh
10521044
Table "public.test_ex_constraints_inh"
10531045
Column | Type | Modifiers | Storage | Stats target | Description
10541046
--------+--------+-----------+---------+--------------+-------------
10551047
c | circle | | plain | |
10561048
Inherits: test_ex_constraints
1057-
Has OIDs: no
10581049

10591050
DROP TABLE test_ex_constraints_inh;
10601051
DROP TABLE test_ex_constraints;
@@ -1071,7 +1062,6 @@ Indexes:
10711062
"test_primary_constraints_pkey" PRIMARY KEY, btree (id)
10721063
Referenced by:
10731064
TABLE "test_foreign_constraints" CONSTRAINT "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
1074-
Has OIDs: no
10751065

10761066
\d+ test_foreign_constraints
10771067
Table "public.test_foreign_constraints"
@@ -1081,7 +1071,6 @@ Has OIDs: no
10811071
Foreign-key constraints:
10821072
"test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
10831073
Child tables: test_foreign_constraints_inh
1084-
Has OIDs: no
10851074

10861075
ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;
10871076
\d+ test_foreign_constraints
@@ -1090,15 +1079,13 @@ ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id
10901079
--------+---------+-----------+---------+--------------+-------------
10911080
id1 | integer | | plain | |
10921081
Child tables: test_foreign_constraints_inh
1093-
Has OIDs: no
10941082

10951083
\d+ test_foreign_constraints_inh
10961084
Table "public.test_foreign_constraints_inh"
10971085
Column | Type | Modifiers | Storage | Stats target | Description
10981086
--------+---------+-----------+---------+--------------+-------------
10991087
id1 | integer | | plain | |
11001088
Inherits: test_foreign_constraints
1101-
Has OIDs: no
11021089

11031090
DROP TABLE test_foreign_constraints_inh;
11041091
DROP TABLE test_foreign_constraints;

src/test/regress/expected/replica_identity.out

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
152152
f
153153
(1 row)
154154

155-
\d test_replica_identity
156-
Table "public.test_replica_identity"
157-
Column | Type | Modifiers
158-
--------+---------+--------------------------------------------------------------------
159-
id | integer | not null default nextval('test_replica_identity_id_seq'::regclass)
160-
keya | text | not null
161-
keyb | text | not null
162-
nonkey | text |
155+
\d+ test_replica_identity
156+
Table "public.test_replica_identity"
157+
Column | Type | Modifiers | Storage | Stats target | Description
158+
--------+---------+--------------------------------------------------------------------+----------+--------------+-------------
159+
id | integer | not null default nextval('test_replica_identity_id_seq'::regclass) | plain | |
160+
keya | text | not null | extended | |
161+
keyb | text | not null | extended | |
162+
nonkey | text | | extended | |
163163
Indexes:
164164
"test_replica_identity_pkey" PRIMARY KEY, btree (id)
165165
"test_replica_identity_expr" UNIQUE, btree (keya, keyb, (3))

src/test/regress/expected/rules.out

-1
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,6 @@ Rules:
26092609
r3 AS
26102610
ON DELETE TO rules_src DO
26112611
NOTIFY rules_src_deletion
2612-
Has OIDs: no
26132612

26142613
--
26152614
-- check alter rename rule

src/test/regress/sql/replica_identity.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ SELECT count(*) FROM pg_index WHERE indrelid = 'test_replica_identity'::regclass
7171

7272
ALTER TABLE test_replica_identity REPLICA IDENTITY FULL;
7373
SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
74-
\d test_replica_identity
74+
\d+ test_replica_identity
7575
ALTER TABLE test_replica_identity REPLICA IDENTITY NOTHING;
7676
SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
7777

0 commit comments

Comments
 (0)