Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/pgFormatter/Beautify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'} } = ();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );

Expand Down
4 changes: 3 additions & 1 deletion t/pg-test-files/expected/brin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion t/pg-test-files/expected/fsm.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion t/pg-test-files/expected/triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down