@@ -32,11 +32,11 @@ use sqlparser_derive::{Visit, VisitMut};
32
32
pub use super :: ddl:: { ColumnDef , TableConstraint } ;
33
33
34
34
use super :: {
35
- display_comma_separated, display_separated, Assignment , ClusteredBy , CommentDef , Expr ,
36
- FileFormat , FromTable , HiveDistributionStyle , HiveFormat , HiveIOFormat , HiveRowFormat , Ident ,
37
- InsertAliases , MysqlInsertPriority , ObjectName , OnCommit , OnInsert , OneOrManyWithParens ,
38
- OrderByExpr , Query , RowAccessPolicy , SelectItem , SqlOption , SqliteOnConflict , TableEngine ,
39
- TableObject , TableWithJoins , Tag , WrappedCollection ,
35
+ display_comma_separated, display_separated, query :: InputFormatClause , Assignment , ClusteredBy ,
36
+ CommentDef , Expr , FileFormat , FromTable , HiveDistributionStyle , HiveFormat , HiveIOFormat ,
37
+ HiveRowFormat , Ident , InsertAliases , MysqlInsertPriority , ObjectName , OnCommit , OnInsert ,
38
+ OneOrManyWithParens , OrderByExpr , Query , RowAccessPolicy , SelectItem , Setting , SqlOption ,
39
+ SqliteOnConflict , TableEngine , TableObject , TableWithJoins , Tag , WrappedCollection ,
40
40
} ;
41
41
42
42
/// CREATE INDEX statement.
@@ -497,6 +497,19 @@ pub struct Insert {
497
497
pub priority : Option < MysqlInsertPriority > ,
498
498
/// Only for mysql
499
499
pub insert_alias : Option < InsertAliases > ,
500
+ /// Settings used for ClickHouse.
501
+ ///
502
+ /// ClickHouse syntax: `INSERT INTO tbl SETTINGS format_template_resultset = '/some/path/resultset.format'`
503
+ ///
504
+ /// [ClickHouse `INSERT INTO`](https://clickhouse.com/docs/en/sql-reference/statements/insert-into)
505
+ pub settings : Option < Vec < Setting > > ,
506
+ /// Format for `INSERT` statement when not using standard SQL format. Can be e.g. `CSV`,
507
+ /// `JSON`, `JSONAsString`, `LineAsString` and more.
508
+ ///
509
+ /// ClickHouse syntax: `INSERT INTO tbl FORMAT JSONEachRow {"foo": 1, "bar": 2}, {"foo": 3}`
510
+ ///
511
+ /// [ClickHouse formats JSON insert](https://clickhouse.com/docs/en/interfaces/formats#json-inserting-data)
512
+ pub format_clause : Option < InputFormatClause > ,
500
513
}
501
514
502
515
impl Display for Insert {
@@ -545,12 +558,18 @@ impl Display for Insert {
545
558
write ! ( f, "({}) " , display_comma_separated( & self . after_columns) ) ?;
546
559
}
547
560
561
+ if let Some ( settings) = & self . settings {
562
+ write ! ( f, "SETTINGS {} " , display_comma_separated( settings) ) ?;
563
+ }
564
+
548
565
if let Some ( source) = & self . source {
549
566
write ! ( f, "{source}" ) ?;
550
567
} else if !self . assignments . is_empty ( ) {
551
568
write ! ( f, "SET " ) ?;
552
569
write ! ( f, "{}" , display_comma_separated( & self . assignments) ) ?;
553
- } else if self . source . is_none ( ) && self . columns . is_empty ( ) {
570
+ } else if let Some ( format_clause) = & self . format_clause {
571
+ write ! ( f, "{format_clause}" ) ?;
572
+ } else if self . columns . is_empty ( ) {
554
573
write ! ( f, "DEFAULT VALUES" ) ?;
555
574
}
556
575
0 commit comments