[fix] issue809 and update unit tests #810
Open
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.
This PR fixes #809.
Looking at the code, I realized that a similar issue was already solved: #784
The tricky part is that BEGIN can be used in two ways:
Case 1
The first way is as a BEGIN TRANSACTION statement:
(For instance, this is valid in MySQL or Postresql, and in this case we do want to split)
Case 2
The second way is as a BEGIN ... END statement when creating a stored procedure, function or trigger.
#784 solved the bug, but only in the case of a CREATE TRIGGER statement, like this one.
The problem is that each SQL dialect has its own syntax (e.g.
WITH FUNCTION
in Trino,CREATE OR REPLACE PROCEDURE
in BigQuery, etc.)Luckily, I found a simple way to tell the two cases apart:
If BEGIN is the first word of the statement, then you are in case 1, otherwise, it's case 2.
There is one edge case with PostgreSQL, though.
For instance, this is valid in psql :
But according to my rule, the first semicolon should not be ignored.
Luckily, it seems you already handled this case because here, everything between the
$_$
keywords is treated as one special block.I had one test failing, the one with this query :
But I suspect that this statement is incorrect.
I checked a few dialects (including MySQL and SQL Server) and I could not find any one besides PostgreSQL where the
DECLARE
statement is before theBEGIN
, not inside. And as we just saw, PostgreSQL requires a$$
keyword.So I edited this test file to put the DECLARE inside the BEGIN ... END block.
I also added a few more tests.