Skip to content

Commit 3dfae91

Browse files
committed
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
1 parent 1da569c commit 3dfae91

File tree

4 files changed

+58
-9
lines changed

4 files changed

+58
-9
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,10 @@ INSERT INTO tbl1 VALUES ($1, $2) \bind 'first value' 'second value' \g
16501650
If the form <literal>\df+</literal> is used, additional information
16511651
about each function is shown, including volatility,
16521652
parallel safety, owner, security classification, access privileges,
1653-
language, source code and description.
1653+
language, internal name (for C and internal functions only),
1654+
and description.
1655+
Source code for a specific function can be seen
1656+
using <literal>\sf</literal>.
16541657
</para>
16551658

16561659
</listitem>

src/bin/psql/describe.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,9 @@ describeFunctions(const char *functypes, const char *func_pattern,
410410
appendPQExpBuffer(&buf,
411411
",\n l.lanname as \"%s\"",
412412
gettext_noop("Language"));
413-
if (pset.sversion >= 140000)
414-
appendPQExpBuffer(&buf,
415-
",\n COALESCE(pg_catalog.pg_get_function_sqlbody(p.oid), p.prosrc) as \"%s\"",
416-
gettext_noop("Source code"));
417-
else
418-
appendPQExpBuffer(&buf,
419-
",\n p.prosrc as \"%s\"",
420-
gettext_noop("Source code"));
413+
appendPQExpBuffer(&buf,
414+
",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
415+
gettext_noop("Internal name"));
421416
appendPQExpBuffer(&buf,
422417
",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
423418
gettext_noop("Description"));

src/test/regress/expected/psql.out

+28
Original file line numberDiff line numberDiff line change
@@ -5247,6 +5247,34 @@ reset work_mem;
52475247
pg_catalog | && | anyarray | anyarray | boolean | overlaps
52485248
(1 row)
52495249

5250+
-- check \df+
5251+
begin;
5252+
-- we have to use functions with a predictable owner name, so make a role
5253+
create role regress_psql_user superuser;
5254+
set session authorization regress_psql_user;
5255+
create function psql_df_internal (float8)
5256+
returns float8
5257+
language internal immutable parallel safe strict
5258+
as 'dsin';
5259+
create function psql_df_sql (x integer)
5260+
returns integer
5261+
security definer
5262+
begin atomic select x + 1; end;
5263+
create function psql_df_plpgsql ()
5264+
returns void
5265+
language plpgsql
5266+
as $$ begin return; end; $$;
5267+
comment on function psql_df_plpgsql () is 'some comment';
5268+
\df+ psql_df_*
5269+
List of functions
5270+
Schema | Name | Result data type | Argument data types | Type | Volatility | Parallel | Owner | Security | Access privileges | Language | Internal name | Description
5271+
--------+------------------+------------------+---------------------+------+------------+----------+-------------------+----------+-------------------+----------+---------------+--------------
5272+
public | psql_df_internal | double precision | double precision | func | immutable | safe | regress_psql_user | invoker | | internal | dsin |
5273+
public | psql_df_plpgsql | void | | func | volatile | unsafe | regress_psql_user | invoker | | plpgsql | | some comment
5274+
public | psql_df_sql | integer | x integer | func | volatile | unsafe | regress_psql_user | definer | | sql | |
5275+
(3 rows)
5276+
5277+
rollback;
52505278
-- check \sf
52515279
\sf information_schema._pg_expandarray
52525280
CREATE OR REPLACE FUNCTION information_schema._pg_expandarray(anyarray, OUT x anyelement, OUT n integer)

src/test/regress/sql/psql.sql

+23
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,29 @@ reset work_mem;
12751275
\do - pg_catalog.int4
12761276
\do && anyarray *
12771277

1278+
-- check \df+
1279+
begin;
1280+
-- we have to use functions with a predictable owner name, so make a role
1281+
create role regress_psql_user superuser;
1282+
set session authorization regress_psql_user;
1283+
1284+
create function psql_df_internal (float8)
1285+
returns float8
1286+
language internal immutable parallel safe strict
1287+
as 'dsin';
1288+
create function psql_df_sql (x integer)
1289+
returns integer
1290+
security definer
1291+
begin atomic select x + 1; end;
1292+
create function psql_df_plpgsql ()
1293+
returns void
1294+
language plpgsql
1295+
as $$ begin return; end; $$;
1296+
comment on function psql_df_plpgsql () is 'some comment';
1297+
1298+
\df+ psql_df_*
1299+
rollback;
1300+
12781301
-- check \sf
12791302
\sf information_schema._pg_expandarray
12801303
\sf+ information_schema._pg_expandarray

0 commit comments

Comments
 (0)