From 875615d8e2a6a380e3aae69b118314ee1bc6a1d9 Mon Sep 17 00:00:00 2001
From: Isaac Morland <isaac.morland@gmail.com>
Date: Tue, 17 Jan 2023 14:17:42 -0500
Subject: [PATCH] Remove source code display from \df+

The column is renamed to "Internal name" and will still show the internal
name for C and Internal functions.
---
 doc/src/sgml/ref/psql-ref.sgml     |  3 ++-
 src/bin/psql/describe.c            | 11 +++--------
 src/test/regress/expected/psql.out | 18 ++++++++++++++++++
 src/test/regress/sql/psql.sql      |  6 ++++++
 4 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index dc6528dc11..afdf8668d6 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1650,7 +1650,8 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
         If the form <literal>\df+</literal> is used, additional information
         about each function is shown, including volatility,
         parallel safety, owner, security classification, access privileges,
-        language, source code and description.
+        language, internal name (for C and Internal language functions only),
+        and description.  Source code can be shown using <literal>\sf</literal>.
         </para>
 
         </listitem>
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c8a0bb7b3a..7199bc0532 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -410,14 +410,9 @@ describeFunctions(const char *functypes, const char *func_pattern,
 		appendPQExpBuffer(&buf,
 						  ",\n l.lanname as \"%s\"",
 						  gettext_noop("Language"));
-		if (pset.sversion >= 140000)
-			appendPQExpBuffer(&buf,
-							  ",\n COALESCE(pg_catalog.pg_get_function_sqlbody(p.oid), p.prosrc) as \"%s\"",
-							  gettext_noop("Source code"));
-		else
-			appendPQExpBuffer(&buf,
-							  ",\n p.prosrc as \"%s\"",
-							  gettext_noop("Source code"));
+		appendPQExpBuffer(&buf,
+						  ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc ELSE NULL END AS \"%s\"",
+						  gettext_noop("Internal name"));
 		appendPQExpBuffer(&buf,
 						  ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
 						  gettext_noop("Description"));
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index 8fc62cebd2..3c11afd915 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -5247,6 +5247,24 @@ reset work_mem;
  pg_catalog | &&   | anyarray      | anyarray       | boolean     | overlaps
 (1 row)
 
+-- check \df+
+-- C
+\df+ utf8_to_iso8859
+                                                                                                                           List of functions
+   Schema   |      Name       | Result data type |                  Argument data types                  | Type | Volatility | Parallel |  Owner  | Security | Access privileges | Language |  Internal name  |                      Description                       
+------------+-----------------+------------------+-------------------------------------------------------+------+------------+----------+---------+----------+-------------------+----------+-----------------+--------------------------------------------------------
+ pg_catalog | utf8_to_iso8859 | integer          | integer, integer, cstring, internal, integer, boolean | func | immutable  | safe     | vagrant | invoker  |                   | c        | utf8_to_iso8859 | internal conversion function for UTF8 to ISO-8859 2-16
+(1 row)
+
+-- Internal and other
+\df+ pg_relation_size
+                                                                                                                 List of functions
+   Schema   |       Name       | Result data type | Argument data types | Type | Volatility | Parallel |  Owner  | Security | Access privileges | Language |  Internal name   |                            Description                             
+------------+------------------+------------------+---------------------+------+------------+----------+---------+----------+-------------------+----------+------------------+--------------------------------------------------------------------
+ pg_catalog | pg_relation_size | bigint           | regclass            | func | volatile   | safe     | vagrant | invoker  |                   | sql      |                  | disk space usage for the main fork of the specified table or index
+ pg_catalog | pg_relation_size | bigint           | regclass, text      | func | volatile   | safe     | vagrant | invoker  |                   | internal | pg_relation_size | disk space usage for the specified fork of a table or index
+(2 rows)
+
 -- check \sf
 \sf information_schema._pg_expandarray
 CREATE OR REPLACE FUNCTION information_schema._pg_expandarray(anyarray, OUT x anyelement, OUT n integer)
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 2da9665a19..d73b2f697f 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -1275,6 +1275,12 @@ reset work_mem;
 \do - pg_catalog.int4
 \do && anyarray *
 
+-- check \df+
+-- C
+\df+ utf8_to_iso8859
+-- Internal and other
+\df+ pg_relation_size
+
 -- check \sf
 \sf information_schema._pg_expandarray
 \sf+ information_schema._pg_expandarray
-- 
2.32.1 (Apple Git-133)

