public inbox for [email protected]  
help / color / mirror / Atom feed
From: Isaac Morland <[email protected]>
To: Alvaro Herrera <[email protected]>
Cc: Justin Pryzby <[email protected]>
Cc: Pavel Stehule <[email protected]>
Cc: Magnus Hagander <[email protected]>
Cc: Tom Lane <[email protected]>
Cc: [email protected]
Subject: Re: Remove source code display from \df+?
Date: Sun, 22 Jan 2023 14:53:48 -0500
Message-ID: <CAMsGm5f6Cyq3sbjyb2hi1MNjadR=Q-XYr-k_06OmE0vYCF-C8g@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAMsGm5dgogOZ5yNc9BsnFM0n4FuykZREmro9f9gvOBWD_D1-2w@mail.gmail.com>
	<[email protected]>

On Sun, 22 Jan 2023 at 14:26, Alvaro Herrera <[email protected]>
wrote:

> On 2023-Jan-22, Isaac Morland wrote:
>
> > I’ve re-written the tests to create a test-specific role and functions so
> > there is no longer a dependency on the superuser name.
>
> This one would fail the sanity check that all roles created by
> regression tests need to have names that start with "regress_".
>

Thanks for the correction. Now I feel like I've skipped some of the
readings!

Updated patch attached. Informally, I am adopting the regress_* policy for
all object types.

> I pondered the notion of going with the flow and just leaving out the
> > tests but that seemed like giving up too easily.
>
> I think avoiding even more untested code is good, so +1 for keeping at
> it.
>


Attachments:

  [application/octet-stream] 0001-Remove-source-code-display-from-df-v5.patch (6.5K, ../CAMsGm5f6Cyq3sbjyb2hi1MNjadR=Q-XYr-k_06OmE0vYCF-C8g@mail.gmail.com/3-0001-Remove-source-code-display-from-df-v5.patch)
  download | inline diff:
From 4cde8f6629b7aefb1d4d648169284e5af0d2489c Mon Sep 17 00:00:00 2001
From: Isaac Morland <[email protected]>
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 | 43 ++++++++++++++++++++++++++++++
 src/test/regress/sql/psql.sql      | 35 ++++++++++++++++++++++++
 4 files changed, 83 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..e487fcd480 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 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..3453a07a18 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -5247,6 +5247,49 @@ reset work_mem;
  pg_catalog | &&   | anyarray      | anyarray       | boolean     | overlaps
 (1 row)
 
+-- check \df+
+CREATE ROLE regress_psql_df;
+CREATE OR REPLACE FUNCTION regress_psql_df_c (integer, integer, cstring, internal, integer)
+  RETURNS VOID
+  LANGUAGE c
+  IMMUTABLE PARALLEL SAFE STRICT
+AS '$libdir/utf8_and_iso8859', 'utf8_to_iso8859';
+CREATE OR REPLACE FUNCTION regress_psql_df_internal (regclass, text)
+  RETURNS bigint
+  LANGUAGE internal
+  PARALLEL SAFE STRICT
+AS 'pg_relation_size';
+CREATE OR REPLACE FUNCTION regress_psql_df_sql ()
+  RETURNS VOID
+BEGIN ATOMIC
+  SELECT NULL;
+END;
+CREATE OR REPLACE FUNCTION regress_psql_df_plpgsql ()
+  RETURNS VOID
+  LANGUAGE plpgsql
+AS $$
+BEGIN
+  RETURN;
+END;
+$$;
+ALTER FUNCTION regress_psql_df_c (integer, integer, cstring, internal, integer)
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_internal (regclass, text)
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_sql ()
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_plpgsql ()
+  OWNER TO regress_psql_df;
+\df+ regress_psql_df_*
+                                                                                                        List of functions
+ Schema |           Name           | Result data type |             Argument data types              | Type | Volatility | Parallel |      Owner      | Security | Access privileges | Language |  Internal name   | Description 
+--------+--------------------------+------------------+----------------------------------------------+------+------------+----------+-----------------+----------+-------------------+----------+------------------+-------------
+ public | regress_psql_df_c        | void             | integer, integer, cstring, internal, integer | func | immutable  | safe     | regress_psql_df | invoker  |                   | c        | utf8_to_iso8859  | 
+ public | regress_psql_df_internal | bigint           | regclass, text                               | func | volatile   | safe     | regress_psql_df | invoker  |                   | internal | pg_relation_size | 
+ public | regress_psql_df_plpgsql  | void             |                                              | func | volatile   | unsafe   | regress_psql_df | invoker  |                   | plpgsql  |                  | 
+ public | regress_psql_df_sql      | void             |                                              | func | volatile   | unsafe   | regress_psql_df | invoker  |                   | sql      |                  | 
+(4 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..43ce373177 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -1275,6 +1275,41 @@ reset work_mem;
 \do - pg_catalog.int4
 \do && anyarray *
 
+-- check \df+
+CREATE ROLE regress_psql_df;
+CREATE OR REPLACE FUNCTION regress_psql_df_c (integer, integer, cstring, internal, integer)
+  RETURNS VOID
+  LANGUAGE c
+  IMMUTABLE PARALLEL SAFE STRICT
+AS '$libdir/utf8_and_iso8859', 'utf8_to_iso8859';
+CREATE OR REPLACE FUNCTION regress_psql_df_internal (regclass, text)
+  RETURNS bigint
+  LANGUAGE internal
+  PARALLEL SAFE STRICT
+AS 'pg_relation_size';
+CREATE OR REPLACE FUNCTION regress_psql_df_sql ()
+  RETURNS VOID
+BEGIN ATOMIC
+  SELECT NULL;
+END;
+CREATE OR REPLACE FUNCTION regress_psql_df_plpgsql ()
+  RETURNS VOID
+  LANGUAGE plpgsql
+AS $$
+BEGIN
+  RETURN;
+END;
+$$;
+ALTER FUNCTION regress_psql_df_c (integer, integer, cstring, internal, integer)
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_internal (regclass, text)
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_sql ()
+  OWNER TO regress_psql_df;
+ALTER FUNCTION regress_psql_df_plpgsql ()
+  OWNER TO regress_psql_df;
+\df+ regress_psql_df_*
+
 -- check \sf
 \sf information_schema._pg_expandarray
 \sf+ information_schema._pg_expandarray
-- 
2.32.1 (Apple Git-133)



view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Remove source code display from \df+?
  In-Reply-To: <CAMsGm5f6Cyq3sbjyb2hi1MNjadR=Q-XYr-k_06OmE0vYCF-C8g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox