From 8c3814f4adbfab99b5d98788dc1e2ab0136a3b8e Mon Sep 17 00:00:00 2001 From: Gilles Darold Date: Wed, 20 Mar 2024 21:41:11 +0700 Subject: [PATCH] Fix handling of the assignement operator := when there is no space between the variabl name and the operator. Thanks to Alexey Samoilov for the report. --- lib/pgFormatter/Beautify.pm | 7 +++++++ t/test-files/ex64.sql | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pgFormatter/Beautify.pm b/lib/pgFormatter/Beautify.pm index 123c635..69d9c04 100755 --- a/lib/pgFormatter/Beautify.pm +++ b/lib/pgFormatter/Beautify.pm @@ -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') diff --git a/t/test-files/ex64.sql b/t/test-files/ex64.sql index 3d88235..0a2004a 100644 --- a/t/test-files/ex64.sql +++ b/t/test-files/ex64.sql @@ -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;