@@ -11329,14 +11329,19 @@ impl<'a> Parser<'a> {
11329
11329
if self.parse_keywords(&[Keyword::DEFAULT, Keyword::VALUES]) {
11330
11330
(vec![], None, vec![], None)
11331
11331
} else {
11332
- let columns = self.parse_parenthesized_column_list(Optional, is_mysql)?;
11332
+ let (columns, partitioned, after_columns) = if !self.peek_subquery_start() {
11333
+ let columns = self.parse_parenthesized_column_list(Optional, is_mysql)?;
11333
11334
11334
- let partitioned = self.parse_insert_partition()?;
11335
- // Hive allows you to specify columns after partitions as well if you want.
11336
- let after_columns = if dialect_of!(self is HiveDialect) {
11337
- self.parse_parenthesized_column_list(Optional, false)?
11335
+ let partitioned = self.parse_insert_partition()?;
11336
+ // Hive allows you to specify columns after partitions as well if you want.
11337
+ let after_columns = if dialect_of!(self is HiveDialect) {
11338
+ self.parse_parenthesized_column_list(Optional, false)?
11339
+ } else {
11340
+ vec![]
11341
+ };
11342
+ (columns, partitioned, after_columns)
11338
11343
} else {
11339
- vec![]
11344
+ Default::default()
11340
11345
};
11341
11346
11342
11347
let source = Some(self.parse_query()?);
@@ -11431,6 +11436,14 @@ impl<'a> Parser<'a> {
11431
11436
}
11432
11437
}
11433
11438
11439
+ /// Returns true if the immediate tokens look like the
11440
+ /// beginning of a subquery. `(SELECT ...`
11441
+ fn peek_subquery_start(&mut self) -> bool {
11442
+ let [maybe_lparen, maybe_select] = self.peek_tokens();
11443
+ Token::LParen == maybe_lparen
11444
+ && matches!(maybe_select, Token::Word(w) if w.keyword == Keyword::SELECT)
11445
+ }
11446
+
11434
11447
fn parse_conflict_clause(&mut self) -> Option<SqliteOnConflict> {
11435
11448
if self.parse_keywords(&[Keyword::OR, Keyword::REPLACE]) {
11436
11449
Some(SqliteOnConflict::Replace)
0 commit comments