-
Notifications
You must be signed in to change notification settings - Fork 3.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
sql: views created using a DB context can't be selected from outside that DB context #9921
Comments
I think it would be fair to normalize names, which would add the missing db name prefix, before storing the query in the view descriptor. |
Right, but do you have any thoughts on how? It feels kind of gross modifying the formatter to have a FmtFlag for database normalization, but I'm not seeing many other answers. |
This needs to be a separate phase than Format(). You need to:
I acknowledge that the 3-step idea above looks simpler than the code needed to do it. The "better solution" is one more use case for an IR that does this normalization stuff without involving all the planNode madness. Unfortunately this will only happen in a few weeks at the earliest... |
A few updates from yesterday's adventures that I wasn't able to send out because I didn't have internet:
For example, it's kind of a fluke, but a simple star select works just fine as columns are added because the view descriptor only lists the original columns as its ResultColumns:
On the other hand, if the * isn't at the end of the query, it can break the view as columns are added:
The logic for expanding stars appears to be a little broader in scope than the logic for normalizing table names, so I'm not sure if there's as well-contained of a fix for it (beyond moving to a semantic representation, of course). |
This goes back to our original conversation about semantic vs syntactic encoding on the RFC PR. We're currently relying on the parser to format a text-based representation of the query to be saved for later, but it's not clear to me that the parser has enough context to qualify the table names in a view's query with their databases if they weren't fully qualified by the user.
It may require some awkward hoop-jumping to persist the properly-qualified name given that the parser doesn't have the session state. Any suggestions on this?
Basic repro example:
@dt @knz
The text was updated successfully, but these errors were encountered: