Skip to content

Commit 2944cf2

Browse files
committed
Fix wierd nested indenting when using multi conditional join with integer 0 value. Thanks to Neszt Tibor for the report.
1 parent de50c80 commit 2944cf2

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

lib/pgFormatter/Beautify.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,7 @@ sub beautify {
32993299
and ( not defined $last or uc($last) ne 'MATCH' ) )
33003300
{
33013301
$self->{'no_break'} = 0;
3302-
if ( !$self->{'_is_in_join'} and ( $last and $last ne ')' ) ) {
3302+
if ( !$self->{'_is_in_join'} and ( defined $last and $last ne ')' ) ) {
33033303
$self->_back( $token, $last ) if ($#{ $self->{'_level_stack'} } < 0 or $self->{'_level'} > $self->{'_level_stack'}[-1]+1);
33043304
}
33053305
if ( $self->{'_has_over_in_join'} ) {
@@ -3332,7 +3332,7 @@ sub beautify {
33323332
$self->_new_line( $token, $last );
33333333
$self->_back( $token, $last )
33343334
if ( $self->{'_has_over_in_join'} );
3335-
$self->{'_has_over_in_join'} = 0;
3335+
$self->{'_has_over_in_join'} = 0;
33363336
}
33373337
$self->_add_token($token);
33383338
$self->{'_is_in_join'} = 1;
@@ -3364,7 +3364,7 @@ sub beautify {
33643364
$self->{'_is_in_join'} = 0;
33653365
if ( !$self->{'_is_in_if'}
33663366
and !$self->{'_is_in_index'}
3367-
and ( !$last or $last !~ /^(?:CREATE)$/i )
3367+
and ( not defined $last or $last !~ /^(?:CREATE)$/i )
33683368
and ( $self->{'_is_in_create'} <= 2 )
33693369
and !$self->{'_is_in_trigger'} )
33703370
{

t/pg-test-files/expected/partition_join.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ FROM
18631863
prt1_l t2
18641864
JOIN prt2_l t3 ON (t2.a = t3.b
18651865
AND t2.c = t3.c)) ss ON t1.a = ss.t2a
1866-
AND t1.c = ss.t2c
1866+
AND t1.c = ss.t2c
18671867
WHERE
18681868
t1.b = 0
18691869
ORDER BY
@@ -1884,7 +1884,7 @@ FROM
18841884
prt1_l t2
18851885
JOIN prt2_l t3 ON (t2.a = t3.b
18861886
AND t2.c = t3.c)) ss ON t1.a = ss.t2a
1887-
AND t1.c = ss.t2c
1887+
AND t1.c = ss.t2c
18881888
WHERE
18891889
t1.b = 0
18901890
ORDER BY

t/test-files/ex78.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ WHERE
3333
ORDER BY
3434
z.worker_id;
3535

36+
CREATE OR REPLACE VIEW test AS
37+
SELECT
38+
*
39+
FROM
40+
test1 AS a
41+
INNER JOIN test2 AS b ON a.field1 = b.field1 AND b.field2 = 'data2' AND b.field3 = 'data3'
42+
INNER JOIN test2 AS b ON a.field1 = b.field1 AND b.field2 = 'data2' AND b.field3 = 0
43+
INNER JOIN test2 AS b ON a.field1 = b.field1 AND b.field2 = 'data2' AND b.field3 = 'data3'
44+
INNER JOIN test2 AS b ON a.field1 = b.field1 AND b.field2 = 'data2' AND b.field3 = 'data3';

t/test-files/expected/ex78.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,21 @@ WHERE
3434
ORDER BY
3535
z.worker_id;
3636

37+
CREATE OR REPLACE VIEW test AS
38+
SELECT
39+
*
40+
FROM
41+
test1 AS a
42+
INNER JOIN test2 AS b ON a.field1 = b.field1
43+
AND b.field2 = 'data2'
44+
AND b.field3 = 'data3'
45+
INNER JOIN test2 AS b ON a.field1 = b.field1
46+
AND b.field2 = 'data2'
47+
AND b.field3 = 0
48+
INNER JOIN test2 AS b ON a.field1 = b.field1
49+
AND b.field2 = 'data2'
50+
AND b.field3 = 'data3'
51+
INNER JOIN test2 AS b ON a.field1 = b.field1
52+
AND b.field2 = 'data2'
53+
AND b.field3 = 'data3';
54+

0 commit comments

Comments
 (0)