Better title output for psql \dt \di etc. commands

From: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Better title output for psql \dt \di etc. commands
Date: 2025-02-03 17:38:39
Message-ID: CAKAnmm+7o93fQV-RFkGaN1QnP-0D4d3JTykD+cLueqjDMKdfag@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Please find attached a patch to enable more intuitive titles when using
psql and doing the following actions:

\dt \di \dv \dm \ds \dE

In other words, everything in listTables()

We still default to "List or relations", but if we know that the user has
requested exactly one specific type of relation, we use that instead. So
instead of

greg=# \dv
List of relations
Schema | Name | Type | Owner
--------+-------------------------+------+-------
public | pg_stat_statements | view | greg
public | pg_stat_statements_info | view | greg

we get:

greg=# \dv
List of views
Schema | Name | Type | Owner
--------+-------------------------+------+-------
public | pg_stat_statements | view | greg
public | pg_stat_statements_info | view | greg
(2 rows)

The same applies for "misses" as well:

greg=# \di
Did not find any indexes.

greg=# \di foo*
Did not find any indexes named "foo*".

I thought about keeping that last one as singular, as it is replacing "Did
not find any relation named", but not only does it make more sense as a
plural given that wildcards can produce multiple relations, it makes the
code cleaner. :)

Inspired by a recent thread[0] over in pgsql-bugs entitled "Bug in psql".
(while not a bug, it is certainly a welcome enhancement, IMHO).

Cheers,
Greg

[0]
https://www.postgresql.org/message-id/CADrHaBEVSYwemoJWtry2%2B82KHy9tZirH2PVfi-uD96R5J8FCsw%40mail.gmail.com

Attachment Content-Type Size
0001-Show-more-intuitive-titles-for-psql-commands.patch application/x-patch 2.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-02-03 17:53:06 Re: Using Expanded Objects other than Arrays from plpgsql
Previous Message Tom Lane 2025-02-03 17:36:48 Re: Using Expanded Objects other than Arrays from plpgsql