Repository navigation
Fix formatting a view's SQL being treated as a column change that drops and re-creates the view. #9838 #10591
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6bb0c70
Fix formatting a view's SQL being treated as a column change that dro…
dpage 910d104
Keep quoted identifiers intact and split at the FROM keyword when che…
dpage d98bd48
Make the view reformat test independent of the PostgreSQL version. #9838
dpage 5d687fe
Skip SQL comments and dollar-quoted strings when checking view column…
dpage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...rowser/server_groups/servers/databases/schemas/views/tests/test_views_split_definition.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| ########################################################################## | ||
| # | ||
| # pgAdmin 4 - PostgreSQL Tools | ||
| # | ||
| # Copyright (C) 2013 - 2026, The pgAdmin Development Team | ||
| # This software is released under the PostgreSQL Licence | ||
| # | ||
| ########################################################################## | ||
|
|
||
| from pgadmin.utils.route import BaseTestGenerator | ||
| from pgadmin.browser.server_groups.servers.databases.schemas.views import \ | ||
| ViewNode | ||
|
|
||
|
|
||
| class ViewsSplitDefinitionTestCase(BaseTestGenerator): | ||
| """The select list compared to decide whether a view must be dropped | ||
| and re-created ignores reformatting, but notices changes to quoted | ||
| identifiers and is not cut short by identifiers containing 'from'.""" | ||
|
|
||
| scenarios = [ | ||
| ('Reformat with different case and whitespace is ignored', dict( | ||
| old=' SELECT id,\n upper(a) AS ua,\n (d)::text AS ds\n' | ||
| ' FROM t1 t;', | ||
| new='SELECT\n\tid,\n\tUPPER(a) AS ua,\n\t(d)::TEXT AS ds\n' | ||
| 'FROM\n\tt1 t;', | ||
| same=True)), | ||
| ('Case change in a quoted identifier is noticed', dict( | ||
| old='SELECT 1 AS "Name" FROM t1', | ||
| new='SELECT 1 AS "NAME" FROM t1', | ||
| same=False)), | ||
| ('Punctuation change in a quoted identifier is noticed', dict( | ||
| old='SELECT 1 AS "a-b" FROM t1', | ||
| new='SELECT 1 AS "ab" FROM t1', | ||
| same=False)), | ||
| ('Quoting an identifier that needs no quotes is ignored', dict( | ||
| old='SELECT id, name FROM t1', | ||
| new='SELECT "id", "name" FROM t1', | ||
| same=True)), | ||
| ('Column removed after one named like FROM is noticed', dict( | ||
| old='SELECT a AS fromage, b FROM t1', | ||
| new='SELECT a AS fromage FROM t1', | ||
| same=False)), | ||
| ('Column removed after valid_from is noticed', dict( | ||
| old='SELECT id, valid_from, name FROM t1', | ||
| new='SELECT id, valid_from FROM t1', | ||
| same=False)), | ||
| ('FROM inside a string literal does not split', dict( | ||
| old="SELECT 'x FROM y' AS a, b FROM t1", | ||
| new="SELECT 'x FROM y' AS a FROM t1", | ||
| same=False)), | ||
| ('FROM inside a block comment does not split', dict( | ||
| old='SELECT a /* from */, b FROM t1', | ||
| new='SELECT a /* from */ FROM t1', | ||
| same=False)), | ||
| ('FROM inside a nested block comment does not split', dict( | ||
| old='SELECT a /* x /* y */ from */, b FROM t1', | ||
| new='SELECT a /* x /* y */ from */ FROM t1', | ||
| same=False)), | ||
| ('FROM inside a line comment does not split', dict( | ||
| old='SELECT a -- from\n, b FROM t1', | ||
| new='SELECT a -- from\nFROM t1', | ||
| same=False)), | ||
| ('Adding or removing a comment is ignored', dict( | ||
| old='SELECT a, /* note */ b -- the end\nFROM t1', | ||
| new='SELECT a, b FROM t1', | ||
| same=True)), | ||
| ('FROM inside a dollar-quoted string does not split', dict( | ||
| old='SELECT $q$ from $$ \' $q$ AS a, b FROM t1', | ||
| new='SELECT $q$ from $$ \' $q$ AS a FROM t1', | ||
| same=False)), | ||
| ('FROM inside an E string with escapes does not split', dict( | ||
| old="SELECT E'it\\'s from' AS a, b FROM t1", | ||
| new="SELECT E'it\\'s from' AS a FROM t1", | ||
| same=False)), | ||
| ('A $ inside an identifier does not start a dollar quote', dict( | ||
| old='SELECT a$q$, b FROM t1', | ||
| new='SELECT a$q$ FROM t1', | ||
| same=False)), | ||
| ] | ||
|
|
||
| def runTest(self): | ||
| old_def = ViewNode._split_definition(self.old) | ||
| new_def = ViewNode._split_definition(self.new) | ||
| self.assertEqual(len(old_def), 2) | ||
| self.assertEqual(old_def[0] == new_def[0], self.same) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.