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 subqueries in FROM and JOIN. #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions bin/q.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,15 @@ def __init__(self, sql):
raise Exception(
'FROM/JOIN is missing a table name after it')

# If there's an open paren, the table is a subquery. There's no name here.
qtable_name = self.sql_parts[idx + 1]
if qtable_name.startswith('('):
idx += 1
continue

# Otherwise, the next part contains the qtable name. In most cases the next part will be only the qtable name.
# We handle one special case here, where this is a subquery as a column: "SELECT (SELECT ... FROM qtable),100 FROM ...".
# In that case, there will be an ending paranthesis as part of the name, and we want to handle this case gracefully.
# We handle one special case here, where this is a subquery such as: "SELECT (SELECT ... FROM qtable),100 FROM ...".
# In that case, there may be an ending paranthesis as part of the name, and we want to handle this case gracefully.
# This is obviously a hack of a hack :) Just until we have
# complete parsing capabilities
if ')' in qtable_name:
Expand Down