From 867903a812a57c4926ea2ca019943b8fcc796a5b Mon Sep 17 00:00:00 2001 From: Alexander Samsig Date: Wed, 25 Mar 2026 15:16:46 +0100 Subject: [PATCH] Fix indentation of RETURNING ... INTO statements. --- lib/pgFormatter/Beautify.pm | 16 ++++++++++++++++ t/pg-test-files/expected/brin.sql | 4 +++- t/pg-test-files/expected/fsm.sql | 4 +++- t/pg-test-files/expected/triggers.sql | 4 +++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/pgFormatter/Beautify.pm b/lib/pgFormatter/Beautify.pm index 9337eb6..54bb87c 100755 --- a/lib/pgFormatter/Beautify.pm +++ b/lib/pgFormatter/Beautify.pm @@ -947,6 +947,7 @@ sub beautify { $self->{'_is_in_between'} = 0; $self->{'_is_in_materialized'} = 0; $self->{'_is_closing_function'} = 0; + $self->{'_is_in_returning'} = 0; @{ $self->{'_begin_level'} } = (); @@ -2594,6 +2595,7 @@ sub beautify { $self->{'_is_in_drop_function'} = 0; $self->{'_current_full_sql_stmt'} = ''; $self->{ '_is_in_return_query' } = 0; + $self->{'_is_in_returning'} = 0; if ( $self->{'_insert_values'} ) { if ( $self->{'_is_in_block'} == -1 @@ -2714,6 +2716,8 @@ sub beautify { $self->{'_is_in_set'} = 1 if ( uc($token) eq 'SET' && $self->{'_current_sql_stmt'} !~ /^(UPDATE|INSERT)$/i ); + + $self->{'_is_in_returning'} = 1 if ( uc($token) eq 'RETURNING' ); # special cases for create partition statement if ( $token =~ /^VALUES$/i && defined $last @@ -3772,6 +3776,18 @@ sub beautify { next; } + if ($self->{'_is_in_returning'} and $token =~ /^INTO$/i) + { + $self->{'_is_in_returning'} = 0; + $self->_back( $token, $last ); + $self->_new_line( $token, $last ); + # Finally add the token without further condition + $self->_add_token( $token, $last ); + $self->_new_line( $token, $last ); + $self->_over( $token, $last ); + next; + } + # Finally add the token without further condition $self->_add_token( $token, $last ); diff --git a/t/pg-test-files/expected/brin.sql b/t/pg-test-files/expected/brin.sql index 7755a0e..10e0dae 100644 --- a/t/pg-test-files/expected/brin.sql +++ b/t/pg-test-files/expected/brin.sql @@ -327,7 +327,9 @@ BEGIN INSERT INTO brin_summarize VALUES (1) RETURNING - ctid INTO curtid; + ctid + INTO + curtid; EXIT WHEN curtid > tid '(2, 0)'; END LOOP; diff --git a/t/pg-test-files/expected/fsm.sql b/t/pg-test-files/expected/fsm.sql index 09a1310..a946291 100644 --- a/t/pg-test-files/expected/fsm.sql +++ b/t/pg-test-files/expected/fsm.sql @@ -64,7 +64,9 @@ BEGIN INSERT INTO fsm_check_size VALUES (num, 'b') RETURNING - ctid INTO curtid; + ctid + INTO + curtid; EXIT WHEN curtid >= tid '(4, 0)'; num = num + 1; diff --git a/t/pg-test-files/expected/triggers.sql b/t/pg-test-files/expected/triggers.sql index eab954c..422c3c7 100644 --- a/t/pg-test-files/expected/triggers.sql +++ b/t/pg-test-files/expected/triggers.sql @@ -1426,7 +1426,9 @@ BEGIN INSERT INTO city_table (city_name, population, country_id) VALUES (NEW.city_name, NEW.population, ctry_id) RETURNING - city_id INTO NEW.city_id; + city_id + INTO + NEW.city_id; END IF; RETURN NEW; END;