Skip to content

Commit 3e39cbe

Browse files
committed
Fix indentation of SELECT ... INTO statements. Thanks to Amanda Graven for the report.
1 parent 9add59b commit 3e39cbe

27 files changed

+358
-128
lines changed

lib/pgFormatter/Beautify.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,6 +3755,17 @@ sub beautify {
37553755
$self->_over( $token, $last ) if ($self->{'_level_stack'}[-1]+1 != $self->{'_level'});
37563756
}
37573757

3758+
if ($self->{'_current_sql_stmt'} eq 'SELECT' and $token =~ /^INTO$/i)
3759+
{
3760+
$self->_back( $token, $last );
3761+
$self->_new_line( $token, $last );
3762+
# Finally add the token without further condition
3763+
$self->_add_token( $token, $last );
3764+
$self->_new_line( $token, $last );
3765+
$self->_over( $token, $last );
3766+
next;
3767+
}
3768+
37583769
# Finally add the token without further condition
37593770
$self->_add_token( $token, $last );
37603771

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,9 @@ FROM
21762176
DROP TABLE attest1;
21772177

21782178
SELECT
2179-
* INTO attest2
2179+
*
2180+
INTO
2181+
attest2
21802182
FROM
21812183
atacc1;
21822184

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ ORDER BY
169169

170170
-- SELECT INTO doesn't support USING
171171
SELECT
172-
INTO tableam_tblselectinto_heap2
172+
INTO
173+
tableam_tblselectinto_heap2
173174
USING heap2
174175
FROM
175176
tableam_tbl_heap2;
@@ -289,7 +290,8 @@ SELECT
289290
FROM
290291
tableam_tbl_heapx;
291292
SELECT
292-
INTO tableam_tblselectinto_heapx
293+
INTO
294+
tableam_tblselectinto_heapx
293295
FROM
294296
tableam_tbl_heapx;
295297
CREATE MATERIALIZED VIEW tableam_tblmv_heapx USING heap2 AS

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,9 @@ DROP TABLE syscol_table;
14691469
--
14701470
SELECT
14711471
unique1,
1472-
unique2 INTO onek_with_null
1472+
unique2
1473+
INTO
1474+
onek_with_null
14731475
FROM
14741476
onek;
14751477

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ FROM
1111
tenk1;
1212

1313
SELECT
14-
* INTO TABLE onek2
14+
*
15+
INTO
16+
TABLE onek2
1517
FROM
1618
onek;
1719

@@ -22,7 +24,9 @@ FROM
2224
slow_emp4000;
2325

2426
SELECT
25-
* INTO TABLE Bprime
27+
*
28+
INTO
29+
TABLE Bprime
2630
FROM
2731
tenk1
2832
WHERE
@@ -71,7 +75,9 @@ VALUES
7175
TABLE city;
7276

7377
SELECT
74-
* INTO TABLE ramp
78+
*
79+
INTO
80+
TABLE ramp
7581
FROM
7682
road
7783
WHERE

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ DECLARE
6565
this_schema text;
6666
BEGIN
6767
SELECT
68-
INTO this_schema relnamespace::regnamespace::text
68+
INTO
69+
this_schema relnamespace::regnamespace::text
6970
FROM
7071
pg_class
7172
WHERE

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ BEGIN
8686
AND oid < 16384
8787
ORDER BY
8888
1 LOOP
89-
EXECUTE 'select min(oid) from ' || relnm INTO lowoid;
89+
EXECUTE 'select min(oid) from ' || relnm
90+
INTO
91+
lowoid;
9092
CONTINUE
9193
WHEN lowoid IS NULL
9294
OR lowoid >= 16384;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ INSERT INTO t1
109109
INSERT INTO t1
110110
VALUES (13);
111111
SELECT
112-
sum(f1) INTO total
112+
sum(f1)
113+
INTO
114+
total
113115
FROM
114116
t1;
115117
DROP TABLE t1;

0 commit comments

Comments
 (0)