From 6583960a6c564a3d24222bc6d6b70fe139733f2e Mon Sep 17 00:00:00 2001 From: Scott Nemes Date: Sun, 25 Jan 2026 15:24:55 -0800 Subject: [PATCH 1/2] Fix issue with colalign and empty resultset --- mycli/main.py | 7 +++++-- test/test_main.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mycli/main.py b/mycli/main.py index 9514f613..060c3a83 100755 --- a/mycli/main.py +++ b/mycli/main.py @@ -1422,8 +1422,11 @@ def get_col_type(col) -> type: col_type = FIELD_TYPES.get(col[1], str) return col_type if type(col_type) is type else str - column_types = [get_col_type(tup) for tup in cur.description] - colalign = [numeric_alignment if x in (int, float, Decimal) else 'left' for x in column_types] + if cur.rowcount > 0: + column_types = [get_col_type(tup) for tup in cur.description] + colalign = [numeric_alignment if x in (int, float, Decimal) else 'left' for x in column_types] + else: + column_types, colalign = [], [] if max_width is not None and isinstance(cur, Cursor): cur = list(cur) diff --git a/test/test_main.py b/test/test_main.py index 22ab2c99..451277a4 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -40,6 +40,20 @@ ] +@dbtest +def test_select_from_empty_table(executor): + run(executor, """create table t1(id int)""") + sql = "select * from t1" + runner = CliRunner() + result = runner.invoke(cli, args=CLI_ARGS + ["-t"], input=sql) + expected = dedent("""\ + +----+ + | id | + +----+ + +----+""") + assert expected in result.output + + def test_is_valid_connection_scheme_valid(executor, capsys): is_valid, scheme = is_valid_connection_scheme("mysql://test@localhost:3306/dev") assert is_valid From 59473b55b2dc8c034ceb3b2629e8fd05a0d48698 Mon Sep 17 00:00:00 2001 From: Scott Nemes Date: Sun, 25 Jan 2026 16:55:01 -0800 Subject: [PATCH 2/2] Updated changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index ca9206be..d8b60894 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ Features Bug Fixes -------- * Better respect case when `keyword_casing` is `auto`. +* Fix error when selecting from an empty table. 1.47.0 (2026/01/24)