-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fixes #35767 to allow for view creation into specified schema from [ Create a view ] in DBManager #58976
Conversation
…ema from [ Create a view ] in DBManager
user_input = view | ||
|
||
if '.' in user_input: # To allow view creation into specified schema | ||
schema, view_name = user_input.split('.') | ||
sql = "CREATE VIEW %s AS %s" % (self.quoteId([schema, view_name]), query) | ||
else: # No schema specified; uses public | ||
sql = "CREATE VIEW %s AS %s" % (self.quoteId(view), query) |
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.
This should probably be hardened a little -- eg if the view name was entered badly with two periods, then we'll get a raw python exception here. How about:
user_input = view | |
if '.' in user_input: # To allow view creation into specified schema | |
schema, view_name = user_input.split('.') | |
sql = "CREATE VIEW %s AS %s" % (self.quoteId([schema, view_name]), query) | |
else: # No schema specified; uses public | |
sql = "CREATE VIEW %s AS %s" % (self.quoteId(view), query) | |
view_name_parts = view.split('.') | |
if len(view_name_parts) == 2: # To allow view creation into specified schema | |
schema, view_name = view_name_parts | |
sql = "CREATE VIEW %s AS %s" % (self.quoteId([schema, view_name]), query) | |
else: # No specific schema specified | |
sql = "CREATE VIEW %s AS %s" % (self.quoteId(view), query) |
I've updated the code as recommended and added an error message should there there be too many periods. Thanks for the suggestion!
🪟 Windows buildsDownload Windows builds of this PR for testing. 🪟 Windows Qt6 buildsDownload Windows Qt6 builds of this PR for testing. |
Thanks! Much more user-friendly. Co-authored-by: Nyall Dawson <[email protected]>
Fixes #35767 to allow for view creation into specified schema from [ Create a view ] in DBManager
Description
Currently, using [ Create a view ] from DBManager for postgres automatically loads the view into the public schema named the entire string. It is reasonable for the user to assume that specifying the schema name as schema.view will create the view into the schema specified. Instead, it's creates a view called schema.view in the public schema. This is generally warned against.
Tested
In order to meet users' expectations, allowed for testing if the string has a "." in the name and to separate the string into two parts to feed into the quoteId which is already set up to accept schema and viewname as a list to process appropriately.
Recommended documentation:
"The Create a View button opens a dialog where you can enter the name for the new view. By default, the view is created in the public schema of the PostgreSQL database. However, you can specify a different schema by using the schema.viewname naming convention."
Backporting is recommended to meet user expectations.
Fixes #35767 to allow for view creation into specified schema from [ Create a view ] in DBManager