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

Correctly find nested tables in a subselect in a join condition #233

Merged
merged 4 commits into from
Nov 12, 2021

Conversation

Tassosb
Copy link
Contributor

@Tassosb Tassosb commented Nov 9, 2021

Expected behavior:

PgQuery.parse('SELECT * FROM foo JOIN bar ON bar.id IN (SELECT id from baz)').tables == ['foo', 'bar', 'baz']

On main, baz isn't being found. On my branch it is, as well as tables that are nested further inside of a join condition (see spec for a query with more nested join conditions and subqueries).

end
end

subselect_items.concat(join_expr_quals)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems to work, but I'd appreciate someone more familiar with the code taking a look. It's possible I may be overlooking something.

Copy link
Member

@lfittl lfittl left a comment

Choose a reason for hiding this comment

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

Hah, I forgot that you can do that (putting subselects inside a JOIN condition) - thanks for the contribution!

@lfittl lfittl merged commit 627ef49 into pganalyze:main Nov 12, 2021
@@ -273,6 +273,7 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
when :join_expr
from_clause_items << { item: next_item[:item].join_expr.larg, type: next_item[:type] }
from_clause_items << { item: next_item[:item].join_expr.rarg, type: next_item[:type] }
subselect_items.concat << next_item[:item].join_expr.quals
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I just realized we are missing a .to_ary here (because of https://bugs.ruby-lang.org/issues/18140, per the comment on top of the function) -- I'll make a quick commit to adjust that

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