Skip to content

Commit

Permalink
Fix handling of the assignement operator := when there is no space
Browse files Browse the repository at this point in the history
between the variabl name and the operator. Thanks to Alexey Samoilov
for the report.
  • Loading branch information
darold committed Mar 20, 2024
1 parent 8e9f2c1 commit 8c3814f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/pgFormatter/Beautify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ sub tokenize_sql
if ($self->{ 'keep_newline' }) {
@query = grep { /(?:\S|^[\r\n]+$)/ } $query =~ m{$re}simxg;
}
# fix := operator that can not be found when attached to the variable name
for (my $i = 0; $i < $#query; $i++) {
if ($query[$i] =~ /:$/ && $query[$i+1] =~ /^=/) {
$query[$i] =~ s/:$//;
$query[$i+1] =~ s/^/:/;
}
}

# Revert position when a comment is before a comma
if ($self->{ 'comma' } eq 'end')
Expand Down
2 changes: 1 addition & 1 deletion t/test-files/ex64.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DECLARE
a_val partitioned_table.a%TYPE;
result partitioned_table%ROWTYPE;
BEGIN
a_val := $1;
a_val:= $1;

SELECT * INTO result FROM partitioned_table WHERE a = a_val;

Expand Down

0 comments on commit 8c3814f

Please sign in to comment.