From a4930c1b021e632fccf5dac5a9d0b1589971340f Mon Sep 17 00:00:00 2001 From: Pawan Singh Kapkoti Date: Mon, 6 Apr 2026 04:27:03 +0100 Subject: [PATCH 1/2] feat: add \dS suffix for system objects (pg_catalog, information_schema) Adds \dtS, \dvS, \dmS, \dsS, \diS, and \dS metacommands that include system objects from pg_catalog and information_schema, matching psql behavior. The existing \dt, \dv, etc. continue to exclude system objects. Implements this by adding a show_system parameter to list_objects(). When True, the pg_catalog/information_schema exclusion filter is skipped (pg_toast is still excluded). Closes dbcli/pgcli#1523 --- pgspecial/dbcommands.py | 43 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/pgspecial/dbcommands.py b/pgspecial/dbcommands.py index 7f02e6c..4367028 100644 --- a/pgspecial/dbcommands.py +++ b/pgspecial/dbcommands.py @@ -432,7 +432,7 @@ def _describe_extension(cur, oid): yield None, cur, headers, cur.statusmessage -def list_objects(cur, pattern, verbose, relkinds): +def list_objects(cur, pattern, verbose, relkinds, show_system=False): """ Returns (title, rows, header, status) @@ -440,6 +440,7 @@ def list_objects(cur, pattern, verbose, relkinds): and list_indexes relkinds is a list of strings to filter pg_class.relkind + show_system includes pg_catalog and information_schema objects (S suffix) """ schema_pattern, table_pattern = sql_name_pattern(pattern) @@ -478,6 +479,11 @@ def list_objects(cur, pattern, verbose, relkinds): if schema_pattern: params["schema_pattern"] = SQL(" AND n.nspname ~ {}").format(schema_pattern) + elif show_system: + params["schema_pattern"] = SQL( + """ + AND n.nspname !~ '^pg_toast' """ + ) else: params["schema_pattern"] = SQL( """ @@ -506,26 +512,61 @@ def list_tables(cur, pattern, verbose): return list_objects(cur, pattern, verbose, ["r", "p", ""]) +@special_command("\\dtS", "\\dtS[+] [pattern]", "List tables, including system tables.") +def list_tables_system(cur, pattern, verbose): + return list_objects(cur, pattern, verbose, ["r", "p", ""], show_system=True) + + @special_command("\\dv", "\\dv[+] [pattern]", "List views.") def list_views(cur, pattern, verbose): return list_objects(cur, pattern, verbose, ["v", "s", ""]) +@special_command("\\dvS", "\\dvS[+] [pattern]", "List views, including system views.") +def list_views_system(cur, pattern, verbose): + return list_objects(cur, pattern, verbose, ["v", "s", ""], show_system=True) + + @special_command("\\dm", "\\dm[+] [pattern]", "List materialized views.") def list_materialized_views(cur, pattern, verbose): return list_objects(cur, pattern, verbose, ["m", "s", ""]) +@special_command("\\dmS", "\\dmS[+] [pattern]", "List materialized views, including system.") +def list_materialized_views_system(cur, pattern, verbose): + return list_objects(cur, pattern, verbose, ["m", "s", ""], show_system=True) + + @special_command("\\ds", "\\ds[+] [pattern]", "List sequences.") def list_sequences(cur, pattern, verbose): return list_objects(cur, pattern, verbose, ["S", "s", ""]) +@special_command("\\dsS", "\\dsS[+] [pattern]", "List sequences, including system.") +def list_sequences_system(cur, pattern, verbose): + return list_objects(cur, pattern, verbose, ["S", "s", ""], show_system=True) + + @special_command("\\di", "\\di[+] [pattern]", "List indexes.") def list_indexes(cur, pattern, verbose): return list_objects(cur, pattern, verbose, ["i", "s", ""]) +@special_command("\\diS", "\\diS[+] [pattern]", "List indexes, including system indexes.") +def list_indexes_system(cur, pattern, verbose): + return list_objects(cur, pattern, verbose, ["i", "s", ""], show_system=True) + + +@special_command( + "\\dS", "\\dS[+] [pattern]", "List all relations, including system objects." +) +def list_all_system(cur, pattern, verbose): + return list_objects( + cur, pattern, verbose, ["r", "p", "v", "m", "S", "s", "f", "i", ""], + show_system=True, + ) + + @special_command("\\df", "\\df[+] [pattern]", "List functions.") def list_functions(cur, pattern, verbose): if verbose: From caf93e3f351aac2316ef8c31ebe70c114760a987 Mon Sep 17 00:00:00 2001 From: Pawan Singh Kapkoti Date: Mon, 6 Apr 2026 06:22:44 +0100 Subject: [PATCH 2/2] docs: add changelog entry for \dS metacommands --- changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.rst b/changelog.rst index bbdcfb0..59c866e 100644 --- a/changelog.rst +++ b/changelog.rst @@ -2,6 +2,10 @@ Unreleased ========== +Features: +--------- +* Add ``\dS`` suffix metacommands (``\dtS``, ``\dvS``, ``\dmS``, ``\dsS``, ``\diS``, ``\dS``) to include system objects from pg_catalog and information_schema, matching psql behavior. + Bug fixes: ---------- * Include relation type/name titles in `\d` and `\d+` describe output so wildcard describe results retain per-relation context.