Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support duplicate column names #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kovshenin
Copy link

Often times, especially during joins, you may end up with columns that have the same name, which currently does not work due to remaining being a dict in _ensure_result_cols with the column name as keys. It later breaks the assertion, since one or more entries would not be a ResultColumn.

Sample query:

SELECT 'foo', 'foo';

This change uses a list with name/index tuples instead of a dict.

Copy link
Owner

@barakalon barakalon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet :)
Thanks for jumping straight to a PR.

How hard would it be to add a unit test for this?
I know most of the tests use a DictCursor, and I'm not sure how that handles duplicate names.

for name in inferred:
remaining.pop(name)
for name, i in inferred:
remaining.remove((name, i))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting hairs here, but this is O(n) when we can probably make it O(1).

Perhaps make remaining a set of (col, i)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants