summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2023-03-02 22:15:00 +0000
committerTom Lane2023-03-02 22:15:13 +0000
commit3dfae91f7a1293e0a57526edcfca8690c176c681 (patch)
tree3b48438aa8c2d0f80860697dde3c692aa1bffa12
parent1da569ca1f1fd08ae728ccde0952b688feff7d9c (diff)
Show "internal name" not "source code" in psql's \df+ command.
Our previous habit of showing the full function body is really pretty unfriendly for tabular viewing of functions, and now that we have \sf and \ef commands there seems no good reason why \df+ has to do it. It still seems to make sense to show prosrc for internal and C-language functions, since in those cases prosrc is just the C function name; but then let's rename the column to "Internal name" which is a more accurate descriptor. Isaac Morland Discussion: https://postgr.es/m/CAMsGm5eqKc6J1=Lwn=ZONG=6ZDYWRQ4cgZQLqMuZGB1aVt_JBg@mail.gmail.com
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml5
-rw-r--r--src/bin/psql/describe.c11
-rw-r--r--src/test/regress/expected/psql.out28
-rw-r--r--src/test/regress/sql/psql.sql23
4 files changed, 58 insertions, 9 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index dc6528dc11..7b8ae9fac3 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1650,7 +1650,10 @@ 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 functions only),
+ and description.
+ Source code for a specific function can be seen
+ using <literal>\sf</literal>.
</para>
</listitem>
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index c8a0bb7b3a..2084f5ccda 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..0f349df344 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -5247,6 +5247,34 @@ reset work_mem;
pg_catalog | && | anyarray | anyarray | boolean | overlaps
(1 row)
+-- check \df+
+begin;
+-- we have to use functions with a predictable owner name, so make a role
+create role regress_psql_user superuser;
+set session authorization regress_psql_user;
+create function psql_df_internal (float8)
+ returns float8
+ language internal immutable parallel safe strict
+ as 'dsin';
+create function psql_df_sql (x integer)
+ returns integer
+ security definer
+ begin atomic select x + 1; end;
+create function psql_df_plpgsql ()
+ returns void
+ language plpgsql
+ as $$ begin return; end; $$;
+comment on function psql_df_plpgsql () is 'some comment';
+\df+ 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 | psql_df_internal | double precision | double precision | func | immutable | safe | regress_psql_user | invoker | | internal | dsin |
+ public | psql_df_plpgsql | void | | func | volatile | unsafe | regress_psql_user | invoker | | plpgsql | | some comment
+ public | psql_df_sql | integer | x integer | func | volatile | unsafe | regress_psql_user | definer | | sql | |
+(3 rows)
+
+rollback;
-- 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..e4ed6cda1f 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -1275,6 +1275,29 @@ reset work_mem;
\do - pg_catalog.int4
\do && anyarray *
+-- check \df+
+begin;
+-- we have to use functions with a predictable owner name, so make a role
+create role regress_psql_user superuser;
+set session authorization regress_psql_user;
+
+create function psql_df_internal (float8)
+ returns float8
+ language internal immutable parallel safe strict
+ as 'dsin';
+create function psql_df_sql (x integer)
+ returns integer
+ security definer
+ begin atomic select x + 1; end;
+create function psql_df_plpgsql ()
+ returns void
+ language plpgsql
+ as $$ begin return; end; $$;
+comment on function psql_df_plpgsql () is 'some comment';
+
+\df+ psql_df_*
+rollback;
+
-- check \sf
\sf information_schema._pg_expandarray
\sf+ information_schema._pg_expandarray