Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Bug fixes:
created by ``uv venv``.
* Read ``alias_map_file`` as UTF-8 (with or without a BOM) instead of the
locale encoding, which made non-ASCII aliases fail on Windows.
* Treat table names in a comma-separated ``FROM`` list the same way as a single
table name, so upper-case names are folded like they are for one table.

Internal:
---------
Expand Down
5 changes: 2 additions & 3 deletions pgcli/packages/parseutils/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ def parse_identifier(item):
# Sometimes Keywords (such as FROM ) are classified as
# identifiers which don't have the get_real_name() method.
try:
schema_name = identifier.get_parent_name()
real_name = identifier.get_real_name()
schema_name, real_name, alias = parse_identifier(identifier)
is_function = allow_functions and _identifier_is_function(identifier)
except AttributeError:
continue
if real_name:
yield TableReference(schema_name, real_name, identifier.get_alias(), is_function)
yield TableReference(schema_name, real_name, alias, is_function)
elif isinstance(item, Identifier):
schema_name, real_name, alias = parse_identifier(item)
is_function = allow_functions and _identifier_is_function(item)
Expand Down
24 changes: 24 additions & 0 deletions tests/parseutils/test_parseutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,27 @@ def test_is_destructive_unconditional_update_string_literal(sql, expected):
)
def test_parse_destructive_warning(warning_level, expected):
assert parse_destructive_warning(warning_level) == expected


@pytest.mark.parametrize('schema', ['', 'PUBLIC.'])
def test_extract_tables_comma_list_matches_standalone_case_folding(schema):
first = schema + 'USERS'
second = schema + 'ORDERS'
assert extract_tables(f'SELECT * FROM {first}, {second}') == (
extract_tables(f'SELECT * FROM {first}') + extract_tables(f'SELECT * FROM {second}')
)


@pytest.mark.parametrize(
"identifier",
[
'"public"."users"',
'"PUBLIC"."USERS"',
'"Foo"',
'users "Alias"',
'users "alias"',
'"users"',
],
)
def test_comma_list_quoted_identifier_matches_standalone(identifier):
assert extract_tables(f"SELECT * FROM {identifier}, orders")[0] == extract_tables(f"SELECT * FROM {identifier}")[0]
21 changes: 21 additions & 0 deletions tests/test_smart_completion_public_schema_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,3 +1021,24 @@ def test_special_name_completion(completer):
display_meta="Toggle timing of commands.",
)
])


@parametrize("completer", completers(casing=False, qualify=no_qual))
@parametrize(
"tables",
[
("USERS", "ORDERS"),
('"PUBLIC"."USERS"', "ORDERS"),
('"Foo"', "orders"),
('"users"', 'orders'),
('"Users"', 'orders'),
('"public"."users"', '"public".orders'),
('users "Alias"', 'orders "Other"'),
('users "alias"', 'orders "other"'),
],
)
def test_comma_list_preserves_identifier_column_completions(completer, tables):
first, second = tables
comma = get_result(completer, f"SELECT from {first}, {second}", len("SELECT "))
joined = get_result(completer, f"SELECT from {first} CROSS JOIN {second}", len("SELECT "))
assert completions_to_set(comma) == completions_to_set(joined)
Loading