forked from catherinedevlin/ipython-sql
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CTE generation when the snippets have trailing semicolons (#544)
- Loading branch information
1 parent
461a5b5
commit 1b2713e
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,34 @@ | ||
def test_trailing_semicolons_removed_from_cte(ip): | ||
ip.run_cell( | ||
"""%%sql --save positive_x | ||
SELECT * FROM number_table WHERE x > 0; | ||
""" | ||
) | ||
|
||
ip.run_cell( | ||
"""%%sql --save positive_y | ||
SELECT * FROM number_table WHERE y > 0; | ||
""" | ||
) | ||
|
||
cell_execution = ip.run_cell( | ||
"""%%sql --save final --with positive_x --with positive_y | ||
SELECT * FROM positive_x | ||
UNION | ||
SELECT * FROM positive_y; | ||
""" | ||
) | ||
|
||
cell_final_query = ip.run_cell( | ||
"%sqlrender final --with positive_x --with positive_y" | ||
) | ||
|
||
assert cell_execution.success | ||
assert cell_final_query.result == ( | ||
"WITH `positive_x` AS (\nSELECT * " | ||
"FROM number_table WHERE x > 0), `positive_y` AS (\nSELECT * " | ||
"FROM number_table WHERE y > 0)\nSELECT * FROM positive_x\n" | ||
"UNION\nSELECT * FROM positive_y;" | ||
) |