@@ -11329,14 +11329,19 @@ impl<'a> Parser<'a> {
1132911329 if self.parse_keywords(&[Keyword::DEFAULT, Keyword::VALUES]) {
1133011330 (vec![], None, vec![], None)
1133111331 } 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)?;
1133311334
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)
1133811343 } else {
11339- vec![]
11344+ Default::default()
1134011345 };
1134111346
1134211347 let source = Some(self.parse_query()?);
@@ -11431,6 +11436,14 @@ impl<'a> Parser<'a> {
1143111436 }
1143211437 }
1143311438
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+
1143411447 fn parse_conflict_clause(&mut self) -> Option<SqliteOnConflict> {
1143511448 if self.parse_keywords(&[Keyword::OR, Keyword::REPLACE]) {
1143611449 Some(SqliteOnConflict::Replace)
0 commit comments