diff --git a/CHANGES.txt b/CHANGES.txt index 5f3c5649..7e095719 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,8 @@ Changes for crash Unreleased ========== +- Sort the output of the ``\dt`` (show tables) command alphabetically. + - Improved the color scheme for the SQL syntax hightlighing. - Dropped support for Python 3.4 and added official support for Python 3.7 diff --git a/crate/crash/command.py b/crate/crash/command.py index 2080b716..5338c81b 100644 --- a/crate/crash/command.py +++ b/crate/crash/command.py @@ -319,7 +319,8 @@ def _show_tables(self, *args): "SELECT format('%s.%s', {schema}, table_name) AS name " "FROM information_schema.tables " "WHERE {schema} NOT IN ('sys','information_schema', 'pg_catalog')" - "{table_filter}".format(schema=schema_name, table_filter=table_filter)) + "{table_filter} " + "ORDER BY 1".format(schema=schema_name, table_filter=table_filter)) @noargs_command def _quit(self, *args): diff --git a/tests/test_commands.py b/tests/test_commands.py index 949974b9..dfb95113 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -133,21 +133,21 @@ def test_post_2_0(self): cmd._exec_and_print = MagicMock() cmd.connection.lowest_server_version = StrictVersion("2.0.0") cmd._show_tables() - cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog') AND table_type = 'BASE TABLE'") + cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog') AND table_type = 'BASE TABLE' ORDER BY 1") def test_post_0_57(self): cmd = CrateShell() cmd._exec_and_print = MagicMock() cmd.connection.lowest_server_version = StrictVersion("0.57.0") cmd._show_tables() - cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog')") + cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog') ORDER BY 1") def test_pre_0_57(self): cmd = CrateShell() cmd._exec_and_print = MagicMock() cmd.connection.lowest_server_version = StrictVersion("0.56.4") cmd._show_tables() - cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', schema_name, table_name) AS name FROM information_schema.tables WHERE schema_name NOT IN ('sys','information_schema', 'pg_catalog')") + cmd._exec_and_print.assert_called_with("SELECT format('%s.%s', schema_name, table_name) AS name FROM information_schema.tables WHERE schema_name NOT IN ('sys','information_schema', 'pg_catalog') ORDER BY 1") class ChecksCommandTest(TestCase):