diff options
author | Andy Schoenberger <akschoenberger@gmail.com> | 2023-02-27 18:20:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 15:20:59 -0800 |
commit | 8ef5392fd1f50591aaaa0a6ea204f7545edceddd (patch) | |
tree | 1647ec9155880835adc44f5f7e4a28bb28dd53cb | |
parent | 0a502accfc5060e032eed5a7d919eb33e3617b2a (diff) |
fix explain output when running with auto-vertical-output or max_width (#1396)
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/explain_output_formatter.py | 3 | ||||
-rw-r--r-- | pgcli/main.py | 3 |
3 files changed, 5 insertions, 2 deletions
diff --git a/changelog.rst b/changelog.rst index 70f76abd..a8b268b0 100644 --- a/changelog.rst +++ b/changelog.rst @@ -20,6 +20,7 @@ Bug fixes: * Fix \ev not producing a correctly quoted "schema"."view" * Fix 'invalid connection option "dsn"' ([issue 1373](https://github.com/dbcli/pgcli/issues/1373)). +* Fix explain mode when used with `expand`, `auto_expand`, or `--explain-vertical-output` ([issue 1393](https://github.com/dbcli/pgcli/issues/1393)). 3.5.0 (2022/09/15): =================== diff --git a/pgcli/explain_output_formatter.py b/pgcli/explain_output_formatter.py index b14cf440..ce45b4f8 100644 --- a/pgcli/explain_output_formatter.py +++ b/pgcli/explain_output_formatter.py @@ -10,7 +10,8 @@ class ExplainOutputFormatter: self.max_width = max_width def format_output(self, cur, headers, **output_kwargs): - (data,) = cur.fetchone() + # explain query results should always contain 1 row each + [(data,)] = list(cur) explain_list = json.loads(data) visualizer = Visualizer(self.max_width) for explain in explain_list: diff --git a/pgcli/main.py b/pgcli/main.py index 800816eb..5626a5ed 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -1602,7 +1602,8 @@ def format_output(title, cur, headers, status, settings, explain_mode=False): first_line = next(formatted) formatted = itertools.chain([first_line], formatted) if ( - not expanded + not explain_mode + and not expanded and max_width and len(strip_ansi(first_line)) > max_width and headers |