Skip to content

Commit

Permalink
Fix bad inversion of HAVING/GROUP BY clauses. Thanks to bhoot929 for …
Browse files Browse the repository at this point in the history
…the report.
  • Loading branch information
darold committed Sep 1, 2017
1 parent 3ec2ea5 commit 6f54e81
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Ora2Pg/PLSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ sub plsql_to_plpgsql
$str =~ s/(OPEN\s+(?:[^;]+?)\s+FOR)\s+([^\s]+\s*;)/$1 EXECUTE $2/isg;

# Normalize HAVING ... GROUP BY into GROUP BY ... HAVING clause
$str =~ s/\bHAVING\b(.*?)\bGROUP BY\b(.*?)((?=UNION|ORDER BY|LIMIT|INTO |FOR UPDATE|PROCEDURE)|$)/GROUP BY$2 HAVING$1/gis;
$str =~ s/\bHAVING\b((?:(?!SELECT|INSERT|UPDATE|DELETE).)*?)\bGROUP BY\b((?:(?!SELECT|INSERT|UPDATE|DELETE|WHERE).)*?)((?=UNION|ORDER BY|LIMIT|INTO |FOR UPDATE|PROCEDURE|\)\s+(?:AS)*[a-z0-9_]+\s+)|$)/GROUP BY$2 HAVING$1/gis;

# Add STRICT keyword when select...into and an exception with NO_DATA_FOUND/TOO_MANY_ROW is present
#$str =~ s/\b(SELECT\b[^;]*?INTO)(.*?)(EXCEPTION.*?(?:NO_DATA_FOUND|TOO_MANY_ROW))/$1 STRICT $2 $3/igs;
Expand Down

0 comments on commit 6f54e81

Please sign in to comment.