Skip to content

Commit 1cf1e3d

Browse files
Copilotgit-hulk
andauthored
Add line break before column list in INSERT INTO formatting (#246)
--------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: git-hulk <4987594+git-hulk@users.noreply.github.com>
1 parent 6d0175c commit 1cf1e3d

6 files changed

Lines changed: 19 additions & 9 deletions

File tree

parser/format.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,10 @@ func (i *InsertStmt) FormatSQL(formatter *Formatter) {
15791579
}
15801580
formatter.WriteExpr(i.Table)
15811581
if i.ColumnNames != nil {
1582-
formatter.WriteByte(whitespace)
1582+
formatter.Break()
1583+
formatter.Indent()
15831584
formatter.WriteExpr(i.ColumnNames)
1585+
formatter.Dedent()
15841586
}
15851587
if i.Format != nil {
15861588
formatter.WriteByte(whitespace)

parser/testdata/dml/format/beautify/insert_select_without_from.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ INSERT INTO t (c) SELECT 1 WHERE 1 = 1;
44

55

66
-- Beautify SQL:
7-
INSERT INTO t (c)
7+
INSERT INTO t
8+
(c)
89
SELECT
910
1
1011
WHERE

parser/testdata/dml/format/beautify/insert_values.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric) VALU
66
(101, 'Granules are the smallest chunks of data read', now() + 5, 3.14159 )
77

88
-- Beautify SQL:
9-
INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric)
9+
INSERT INTO helloworld.my_first_table
10+
(user_id, message, timestamp, metric)
1011
VALUES
1112
(101, 'Hello, ClickHouse!', now(), -1.0),
1213
(102, 'Insert a lot of rows per batch', yesterday(), 1.41421),

parser/testdata/dml/format/beautify/insert_with_format.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ INSERT INTO table_name (col1, col2) VALUES (1, 2) FORMAT Native;
66

77
-- Beautify SQL:
88
INSERT INTO `_test_1345# $.ДБ`.`2. Таблица №2`;
9-
INSERT INTO "db"."table_name" (col1, col2)
9+
INSERT INTO "db"."table_name"
10+
(col1, col2)
1011
VALUES
1112
(1, 2);
12-
INSERT INTO `_test_1345# $.ДБ`.`2. Таблица №2` (col1, col2);
13-
INSERT INTO table_name (col1, col2)
13+
INSERT INTO `_test_1345# $.ДБ`.`2. Таблица №2`
14+
(col1, col2);
15+
INSERT INTO table_name
16+
(col1, col2)
1417
VALUES
1518
(1, 2);

parser/testdata/dml/format/beautify/insert_with_keyword_placeholder.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ INSERT INTO t (c) VALUES ({name :String});
44

55

66
-- Beautify SQL:
7-
INSERT INTO t (c)
7+
INSERT INTO t
8+
(c)
89
VALUES
910
({name:String});

parser/testdata/dml/format/beautify/insert_with_placeholder.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ INSERT INTO test_with_typed_columns (id, created_at)
1010
VALUES ({id: Int32}, {created_at: DateTime64(6)});
1111

1212
-- Beautify SQL:
13-
INSERT INTO t0 (user_id, message, timestamp, metric)
13+
INSERT INTO t0
14+
(user_id, message, timestamp, metric)
1415
VALUES
1516
(?, ?, ?, ?),
1617
(?, ?, ?, ?),
1718
(?, ?, ?, ?),
1819
(?, ?, ?, ?);
19-
INSERT INTO test_with_typed_columns (id, created_at)
20+
INSERT INTO test_with_typed_columns
21+
(id, created_at)
2022
VALUES
2123
({id:Int32}, {created_at:DateTime64(6)});

0 commit comments

Comments
 (0)