-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: SubSelect can be used as select statement #350
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,14 @@ func trimSQL(sql string) string { | |
} | ||
break | ||
} | ||
// Trim leading '('. For `(select 1);` is also a query. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If trim '(', any need to trim ')' suffix? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, We judge if the statement is a query only by the prefix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then sql will be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only used to check if sql is query in interpreter. And the trimed sql text will not be used outside this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PTAL @qiuyesuifeng |
||
for { | ||
s := strings.TrimPrefix(sql, "(") | ||
if len(s) == len(sql) { | ||
break | ||
} | ||
sql = s | ||
} | ||
return sql | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here may be `'(' SelectStmt ')', not SubSelect, in MySQL, SubSelect is not the same as select.
And you can see the MySQL parser that it uses select too, not sub select.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add '(' SelectStmt ')' into SelectStmt rule, but I got unresolveable confliction.