@@ -32,11 +32,11 @@ use sqlparser_derive::{Visit, VisitMut};
3232pub use super :: ddl:: { ColumnDef , TableConstraint } ;
3333
3434use 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 ,
4040} ;
4141
4242/// CREATE INDEX statement.
@@ -497,6 +497,19 @@ pub struct Insert {
497497 pub priority : Option < MysqlInsertPriority > ,
498498 /// Only for mysql
499499 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 > ,
500513}
501514
502515impl Display for Insert {
@@ -545,12 +558,18 @@ impl Display for Insert {
545558 write ! ( f, "({}) " , display_comma_separated( & self . after_columns) ) ?;
546559 }
547560
561+ if let Some ( settings) = & self . settings {
562+ write ! ( f, "SETTINGS {} " , display_comma_separated( settings) ) ?;
563+ }
564+
548565 if let Some ( source) = & self . source {
549566 write ! ( f, "{source}" ) ?;
550567 } else if !self . assignments . is_empty ( ) {
551568 write ! ( f, "SET " ) ?;
552569 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 ( ) {
554573 write ! ( f, "DEFAULT VALUES" ) ?;
555574 }
556575
0 commit comments