From c505bfe6acf385e6064a180a7aa4a73b6d00ac7f Mon Sep 17 00:00:00 2001
From: Shinya Kato <shinya11.kato@gmail.com>
Date: Sun, 16 Aug 2026 13:43:34 +0900
Subject: [PATCH v1] psql: Fix \d+ display of REPLICA IDENTITY NOTHING

Commit 18954ce7f69 replaced hard-coded relreplident characters in
describe.c with REPLICA_IDENTITY_* macros, but mistakenly used
REPLICA_IDENTITY_DEFAULT instead of REPLICA_IDENTITY_NOTHING when
choosing the string to print.  As a result, \d+ on a table with
REPLICA IDENTITY NOTHING showed "Replica Identity: ???".

Fix the comparison and add regression test coverage for the \d+
footer of such a table, which was previously tested only for FULL.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by:
Backpatch-through: 18
Discussion: https://postgr.es/m/
---
 src/bin/psql/describe.c                       |  2 +-
 .../regress/expected/replica_identity.out     | 24 +++++++++++++++++++
 src/test/regress/sql/replica_identity.sql     |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index afe4b323a7b..063e2555814 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3661,7 +3661,7 @@ describeOneTableDetails(const char *schemaname,
 			printfPQExpBuffer(&buf, "%s: %s",
 							  s,
 							  tableinfo.relreplident == REPLICA_IDENTITY_FULL ? "FULL" :
-							  tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ? "NOTHING" :
+							  tableinfo.relreplident == REPLICA_IDENTITY_NOTHING ? "NOTHING" :
 							  "???");
 
 			printTableAddFooter(&cont, buf.data);
diff --git a/src/test/regress/expected/replica_identity.out b/src/test/regress/expected/replica_identity.out
index 87feaadbb28..1560cd04125 100644
--- a/src/test/regress/expected/replica_identity.out
+++ b/src/test/regress/expected/replica_identity.out
@@ -187,6 +187,30 @@ SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
  n
 (1 row)
 
+\d+ test_replica_identity
+                                                Table "public.test_replica_identity"
+ Column |  Type   | Collation | Nullable |                      Default                      | Storage  | Stats target | Description 
+--------+---------+-----------+----------+---------------------------------------------------+----------+--------------+-------------
+ id     | integer |           | not null | nextval('test_replica_identity_id_seq'::regclass) | plain    |              | 
+ keya   | text    |           | not null |                                                   | extended |              | 
+ keyb   | text    |           | not null |                                                   | extended |              | 
+ nonkey | text    |           |          |                                                   | extended |              | 
+Indexes:
+    "test_replica_identity_pkey" PRIMARY KEY, btree (id)
+    "test_replica_identity_expr" UNIQUE, btree (keya, keyb, (3))
+    "test_replica_identity_hash" hash (nonkey)
+    "test_replica_identity_keyab" btree (keya, keyb)
+    "test_replica_identity_keyab_key" UNIQUE, btree (keya, keyb)
+    "test_replica_identity_nonkey" UNIQUE, btree (keya, nonkey)
+    "test_replica_identity_partial" UNIQUE, btree (keya, keyb) WHERE keyb <> '3'::text
+    "test_replica_identity_unique_defer" UNIQUE CONSTRAINT, btree (keya, keyb) DEFERRABLE
+    "test_replica_identity_unique_nondefer" UNIQUE CONSTRAINT, btree (keya, keyb)
+Not-null constraints:
+    "test_replica_identity_id_not_null" NOT NULL "id"
+    "test_replica_identity_keya_not_null" NOT NULL "keya"
+    "test_replica_identity_keyb_not_null" NOT NULL "keyb"
+Replica Identity: NOTHING
+
 ---
 -- Test that ALTER TABLE rewrite preserves nondefault replica identity
 ---
diff --git a/src/test/regress/sql/replica_identity.sql b/src/test/regress/sql/replica_identity.sql
index b202b30ae2b..4ebb097f282 100644
--- a/src/test/regress/sql/replica_identity.sql
+++ b/src/test/regress/sql/replica_identity.sql
@@ -77,6 +77,7 @@ SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
 \d+ test_replica_identity
 ALTER TABLE test_replica_identity REPLICA IDENTITY NOTHING;
 SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
+\d+ test_replica_identity
 
 ---
 -- Test that ALTER TABLE rewrite preserves nondefault replica identity
-- 
2.47.3

